2
It is possible to insert an animated element in the DOM
synchronized? i.e., when inserting the current state is maintained and not reset as in the example below...
function add() {
let ctn = document.getElementById('ctn');
ctn.insertAdjacentHTML('beforeend', '<div class="pulse">teste</div>');
}
#ctn {
width: 100px;
background-color: green;
}
.pulse {
animation: pulse 0.7s infinite;
padding: 10px;
margin: 0 auto;
display: table;
animation-direction: alternate;
-webkit-animation-name: pulse;
animation-name: pulse;
}
@-webkit-keyframes pulse {
0% {
-webkit-background-color: rgba(0,0,0,0);
}
100% {
-webkit-background-color: rgba(255,255,255,0.5);
}
}
@keyframes pulse {
0% {
background-color: rgba(0,0,0,0);
}
100% {
background-color: rgba(255,255,255,0.5);
}
}
<div id="ctn">
<div class="pulse">teste</div>
</div>
<button onclick="add()" >
Inserir
</button>