Вот соответствующий код:
// Javascript
// delete formule
$('body').on('click', '.del-formule', function(event) {
$(this).parent().remove();
// collapsible
for (var i=0; i<2; i++)
{
document.getElementById('collapsible').classList.toggle("active");
var content = document.getElementById("content");
if (content.style.maxHeight){
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
}
}
});
/* CSS */
.collapsible {
width: 100%;
background-color: #eee;
}
.content {
padding: 0 18px;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
background-color: #f1f1f1;
}
.collapsible:after {
content: '\02795'; /* Unicode character for "plus" sign (+) */
font-size: 13px;
color: white;
float: right;
margin-left: 5px;
}
.collapsible.active:after {
content: "\2796"; /* Unicode character for "minus" sign (-) */
}
Я пытаюсь анимировать следующее: изображение, чтобы показать, что я хочу оживить
Поэтому, когда я нажимаю кнопку Supprimer (означает «Удалить»), я хочу анимировать удаление div
Прямо сейчас, он просто удаляет div
напрямую без анимации
Я подумал, что, может быть, если я закрою и снова открою складной объект, он оживит его (это то, что в моем коде), но это не работает
Проверьте фрагмент ниже, чтобы показать пример
Спасибо за любую помощь! :) Хорошего дня
// collapsible
var coll = document.getElementsByClassName("collapsible");
var i;
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
if (content.style.maxHeight){
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
}
});
}
// add formule
$('body').on('click', '.ajout-formule', function() {
const $formule = $('<div>').addClass('div-formule');
const $ligne_formule = $('<div>').addClass('ligne-formule');
const $btn_formule = $('<th>');
const $tableau_formule = $('<table class="table tabform" id="formule">');
const $head_formule = $('<thead>');
const $tr_formule = $('<tr>');
$btn_formule.append('<button type="button" class="btn spr-champs"><i class="fas fa-trash"></i></button>');
$btn_formule.append('<button class="btn nbr-champs" type="button"><i class="fas fa-sort-numeric-down"></i></button>');
$btn_formule.append('<button class="btn list-champs" type="button"><i class="far fa-list-alt"></i></button>');
$btn_formule.append('<input type="number" name="champs" id="champs" class="form-control pull-left" value="0"/>');
$tr_formule.append('<th><input type="text" name="titre-formule" id="titre-formule" class="form-control pull-left" /></th>');
$tr_formule.append('<th style="width:16px;padding-bottom: 16px;"><i class="fas fa-equals"></i></th>');
$tr_formule.append($btn_formule);
$head_formule.append($tr_formule);
$tableau_formule.append($head_formule);
$ligne_formule.append('<label class="panel-heading">Introduisez la formule : </label>');
$ligne_formule.append($tableau_formule);
$formule.append($ligne_formule);
$formule.append('<span id="error_formule" class="text-danger"></span>');
$formule.append('<span id="success_formule" class="text-danger"></span>');
$formule.append('<button type="button" class="btn ajout-champs"><i class="fas fa-plus-circle"> Ajouter un champ</i></button>');
$formule.append('<button type="button" class="btn save-formule"><i class="fas fa-check-square"> Enregistrer</i></button>');
$formule.append('<button type="button" class="btn del-formule"><i class="fas fa-trash"> Supprimer</i></button>');
$(this).parent().find('.add-formule').append($formule);
// collapsible
for (var i=0; i<2; i++)
{
document.getElementById('collapsible').classList.toggle("active");
var content = document.getElementById("content");
if (content.style.maxHeight){
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
}
}
});
// delete formule
$('body').on('click', '.del-formule', function(event) {
$(this).parent().remove();
// METTRE A JOUR LES LISTES EN ENLEVANT LA FORMULE
// collapsible
for (var i=0; i<2; i++)
{
document.getElementById('collapsible').classList.toggle("active");
var content = document.getElementById("content");
if (content.style.maxHeight){
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
}
}
});
/* Style the header with a grey background and some padding */
* {box-sizing: border-box;}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.header, .collapsible {
overflow: hidden;
background-color: #f1f1f1;
padding: 20px 10px;
}
.header a, .panel-body button.collapsible {
float: left;
color: black;
text-align: center;
padding: 12px;
text-decoration: none;
font-size: 18px;
line-height: 25px;
border-radius: 4px;
}
.header a.logo, .panel-body button.collapsible {
font-size: 25px;
font-weight: bold;
}
.header a:hover, .panel-body button.collapsible:hover {
background-color: #ddd;
color: black;
}
.header a.active {
background-color: dodgerblue;
color: white;
}
.header-right {
float: right;
}
@media screen and (max-width: 500px) {
.header a, .panel-body button.collapsible {
float: none;
display: block;
text-align: left;
}
.header-right {
float: none;
}
}
.contenuaccueil {
text-align: center;
position : absolute;
width : 100%;
color : black;
top:50%;
left:50%;
transform:translate(-50%,-50%);
}
.background
{
margin-top : 10%;
margin-bottom : 10%;
position:relative;
text-align: center;
}
.img
{
background-repeat: repeat-x;
width: 100%;
height: auto;
text-align: center;
}
footer {
text-align : center;
padding-top: 10px;
padding-bottom: 0px;
bottom:0;
width:100%;
color : #A5A5A5;
font-family : "Lato", sans-serif;
font-size : 15px;
font-weight : 400;
text-transform : uppercase;
text-decoration : none;
letter-spacing : 3px;
}
.box
{
width:800px;
margin:0 auto;
}
.active_tab1
{
background-color:#fff;
color:#333;
font-weight: 600;
}
.inactive_tab1
{
background-color: #f5f5f5;
color: #333;
cursor: not-allowed;
}
.has-error
{
border-color:#cc0000;
background-color:#ffff99;
}
/* Styles go here */
.table-content {
padding: 20px;
}
.form-control {
width: 90px;
}
/* Style buttons */
.ajout-lig,.ajout-col,.ajout-graph,.ajout-formule,.save-formule,.ajout-champs, .del-formule {
background-color: DodgerBlue; /* Blue background */
border: none; /* Remove borders */
color: white; /* White text */
padding: 12px 16px; /* Some padding */
font-size: 16px; /* Set a font size */
cursor: pointer; /* Mouse pointer on hover */
border-radius: 5px;
margin-bottom: 1%;
}
/* Darker background on mouse-over */
.ajout-lig:hover,.ajout-col:hover,.ajout-graph,.ajout-formule,.save-formule,.ajout-champs, .del-formule {
background-color: RoyalBlue;
}
.graph, .formule {
display: block;
margin : 0.75%;
width: 50%;
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
color: #555;
background-color: #fff;
background-image: none;
border: 1px solid #ddd;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
-webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
-o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
}
.add, .add-formule {
background-color: #fff;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
}
.div-graph, .div-formule {
padding: 15px;
background-color: #fff;
background-image: none;
border: 1px solid #ddd;
border-radius: 4px;
}
.grad, .axe-x, .axe-y {
width: 19.7%;
display : initial;
}
.grad {
width: 15%;
margin-bottom: 5%;
}
.collapsible {
width: 100%;
background-color: #eee;
}
.content {
padding: 0 18px;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
background-color: #f1f1f1;
}
.collapsible:after {
content: '\02795'; /* Unicode character for "plus" sign (+) */
font-size: 13px;
color: white;
float: right;
margin-left: 5px;
}
.collapsible.active:after {
content: "\2796"; /* Unicode character for "minus" sign (-) */
}
#previous_btn_personal_details, #btn_personal_details, .ajout-champs, .save-formule, .del-formule{
margin-top : 2.5%;
}
.save-formule, .del-formule{
margin-left:1%;
float:right;
}
.operateur {
font-family: FontAwesome, sans-serif;
-moz-appearance: none;
-webkit-appearance: none;
}
.operateur::-ms-expand{
display:none;
}
.add-formule, .div-formule{
background-color: #f1f1f1;
}
.div-formule{
margin-bottom: 2%;
}
.center{
display:table;
margin:0 auto;
}
<html>
<head>
<title>Innovatech</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="css/custom.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://kit.fontawesome.com/38b99a3f0e.js" crossorigin="anonymous"></script>
</head>
<body>
<button type="button" class="collapsible" id="collapsible">Gérer les formules</button>
<div class="form-group content" id="content">
<br />
<button type="button" class="ajout-formule"><i class="fas fa-plus-circle"> Ajouter une formule</i></button>
<div class="panel-body add-formule">
</div>
</div>
</body>