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

前端 未结 1 525
感动是毒
感动是毒 2020-11-29 08:05

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 wh

相关标签:
1条回答
  • 2020-11-29 08:22

    Bind the appropriate events to the element, e.g.

    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, e.g. webkitAnimationEnd

    0 讨论(0)
提交回复
热议问题