You can set the property of the animation
for "none"
and use setTimeout
which will empty the property of animation
for empty ""
and then it will inherit the CSS property again.
Example:
variavel = document.getElementById("butt");
variavel.onclick = function efeito() {
var e = document.getElementById("div");
e.style.animation = "none";
setTimeout(function() {
e.style.animation = "";
}, 100);
}
div {
width: 100px;
height: 100px;
background-color: red;
animation: nomeAnimacao 4s linear;
}
@keyframes nomeAnimacao {
0% {background-color: red;}
25% {background-color: yellow;}
50% {background-color: blue;}
100% {background-color: green;}
}
<div id="div"></div>
<br>
<button id="butt" type="button">Reiniciar</button>
Edit
When you arrow "none"
in an animation, it is automatically canceled, returning to its initial state. When emptying the style, it takes on the CSS style and restarts. See in the image that the style accepts none
:
In the case of other styles, such as width
, the behavior is similar, except that the width
unaccepted none
. Take an example:
variavel = document.getElementById("dvd");
variavel.onclick = function efeito() {
var e = document.getElementById("div");
e.style.width = "100px";
setTimeout(function() {
e.style.width = "";
}, 2000);
}
div{
width: 300px;
height: 50px;
background: red;
}
<div id="div">Clique no botão e aguarde 2s</div>
<input type="button" value="ok" id="dvd">
So whenever I empty a css property of some element, it goes back to the pattern that was set in the stylesheet?
– João
I’ll even put an example in the answer to that with another style
– Sam