I have a simple animation class in css:
.slides-animation {
-webkit-transition: 1s ease-in-out;
-moz-transition: 1s ease-in-out;
-o-transition: 1s ease-in-out;
transition: 1s ease-in-out;
}
So I can toggle it in a div with classList.add
and classList.remove
. It's normaly active, but I want to remove it, call a function and add it again.
element.classList.remove("slides-animation");
moveNow(element); // Update the translate(x,y) coordinates of the element.
element.classList.add("slides-animation");
But it didnt work as expected. The animation is still there. I managed to remove it by adding a timeout this way:
element.classList.remove("slides-animation");
moveNow(element); // Update the translate(x,y) coordinates of the element.
setTimeout(function(){element.classList.add("slides-animation")}, 0)
Now, the element will translate to a new (x,y) with no animation. How is this working ?
I have read that by using timeout in this way you will assure that one function will be executed after the other. But, how was the class added again before moveTo(element)
returned ?