如何检测时,CSS动画,并开始使用JavaScript结束?

如何检测时,CSS动画,并开始使用JavaScript结束?

问题描述:

我是用动画的JavaScript元素。我发现它简单用CSS3做。

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

使用JavaScript你怎么能当一个CSS动画已经开始发现,当它已经结束?有没有在所有的什么办法?

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, 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

请注意:您可能需要添加相应的prefixed事件为好,例如 webkitAnimationEnd

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