What I do:
When I remove the class just like
element.classList.remove('classname')
there are no transition, but when I set a timeout with 0s delay, it works:
setTimeout(function() { element.classList.remove('classname'); }, 0);
Why? How can I avoid setTimeout function or is it normal to use it?
Example: http://jsfiddle.net/JHevJ/1/
Because you're removing the class before the screen calculates the redrawing of elements. You're removing it before it's shown as that class in the first place, so it doesn't think an animation is necessary.
The timeout makes it so it "waits" 0 milliseconds and then removes the class, which lets it show the element with the class first, "wait" 0 time and then remove the class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With