Starting a css3 animation from js | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Starting a css3 animation from js

I just tried doing this and found a solution online adding and removing classes that define the animation to the element in js. but this method does not work when I try to start the animation again (at least in sololearn Output it does not). any suggestions? the Code I tried:

30th Aug 2017, 7:50 AM
Fabian Schipp
Fabian Schipp - avatar
1 Answer
+ 7
Browser can't detect your class change, as you perform changing to 'reset' class just before setting again 'anim' class: technically, browsers consider that there's no change ;P You can fix it, by setting again your 'anim' class inside a setTimeout() call, even with a small delay value, to let time to browser to update the first class changement ('reset') and only then change it again to 'anim' one: // textHolder.className = "animClass"; setTimeout(function() { this.className="animClass"; }.bind(textHolder),0);
30th Aug 2017, 8:11 AM
visph - avatar