你可以做一些事情,检查动画是否完成然后继续前进,有几种方法可以做到这一点。您可以根据需要使用我的以下模块化功能来检查动画或过渡是否完成。
/*
* @support check if animation is finished
*/
var whichAnimationEvent = function whichAnimationEvent() {
var t,
el = document.createElement("fakeelement");
var animations = {
"animation": "animationend",
"OAnimation": "oAnimationEnd",
"MozAnimation": "animationend",
"WebkitAnimation": "webkitAnimationEnd"
}
for (t in animations) {
if (el.style[t] !== undefined) {
return animations[t];
}
}
}
/*
* @support check if transition is finished
*/
var whichTransitionEvent = function whichTransitionEvent() {
var t,
el = document.createElement("fakeelement");
var transitions = {
"transition": "transitionend",
"OTransition": "oTransitionEnd",
"MozTransition": "transitionend",
"WebkitTransition": "webkitTransitionEnd"
}
for (t in transitions) {
if (el.style[t] !== undefined) {
return transitions[t];
}
}
}
这是一个示例http://codepen.io/yoeman/pen/QGPMQz
希望这可以帮助!