简体   繁体   中英

How do you detect when CSS animations start and end with JavaScript?

I was used to animating elements with JavaScript. I found it simpler to do it with CSS3.

Using JavaScript how can you detect when a CSS animation has started and when it has ended? Is there any way at all?

Bind the appropriate events to the element, eg

el.addEventListener("animationstart", function() {}, false);
el.addEventListener("animationend", function() {}, false);
el.addEventListener("animationiteration", function() {}, false);

https://developer.mozilla.org/en-US/docs/CSS/Tutorials/Using_CSS_animations#Using_animation_events

Note: You may need to add the appropriate prefixed-events as well, eg webkitAnimationEnd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM