+ 3

Hello everyone!

I would like to know how to repeat animation on event click (jQuery). can anyone help me please thank you! :-)

11th Jun 2017, 2:11 PM
Nick Dome
Nick Dome - avatar
2 Réponses
+ 3
<!-- Not using JQuery, but principle is to define animation for a specific class name, and onclick, delete the class name, set minimal timeout (so browser take account of modified class element) after wich set again the class name to the element: --> <!DOCTYPE html> <html> <head> <style> #obj { position:relative; width:10vw; height:10vw; background:orange; } .anim { animation:anim 3s linear forwards; } @keyframes anim { from { left:0; } to { left:90vw; } } </style> </head> <body> <div id="obj" class="anim" onclick="this.className=''; window.setTimeout(function(self){self.className='anim';},0,this)"></div> </body> </html>
11th Jun 2017, 8:14 PM
visph
visph - avatar
+ 2
thank you! that help a lot🙂
11th Jun 2017, 11:07 PM
Nick Dome
Nick Dome - avatar