Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a callback on completion of a CSS3 animation?

Is there any way to implement a callback function in case of css3 animation? In case of Javascript animation its possible but not finding any way to do it in css3.

One way I could see is to execute callback after the animation duration but that doesn't make sure that it will always be called right after the animation ends. It will depend on the browser UI queue. I want a more robust method. Any clue?

like image 304
alter Avatar asked May 31 '11 10:05

alter


1 Answers

Yes, there is. The callback is an event, so you must add an event listener to catch it. This is an example with jQuery:

$("#sun").bind('oanimationend animationend webkitAnimationEnd', function() {     alert("fin")  }); 

Or pure js:

element.addEventListener("webkitAnimationEnd", callfunction,false); element.addEventListener("animationend", callfunction,false); element.addEventListener("oanimationend", callfunction,false); 

Live demo: http://jsfiddle.net/W3y7h/

like image 110
methodofaction Avatar answered Oct 20 '22 18:10

methodofaction