javascript - 如何检查我的 css 动画是否完成?

标签 javascript jquery html css

我正在尝试检测我的 CSS 动画是否在我的应用中结束。

我有类似下面的东西

  animation.prototype.nextStage = function(){
       this.ball.show().addClass('stage' + this.stage); //start the animation
       this.ball.on('animationend mozanimationend webkitAnimationEnd oAnimationEnd msanimationend',function(){
            //when animation is ended, do something for animation item itself….
        })
    }

   animation.prototype.isEnded = function(){
     // now sure how to check if the animation is ended outside of the animation obj.
    }


 function main(){
    this.ball = new animation ();
 }

main.prototype.checkAnimation = function(){
    this.ball.nextStage();
    if(this.ball.isEnded){
      //do stuff for something that is not part of animation items..
    }
}

我不确定如何检查我的球动画是否在我的主要对象中完成。谁能帮我解决这个问题?非常感谢!

最佳答案

这样您每次调用 nextStage 时都可以添加新的事件处理程序。

使用类似的东西会更好:

function animation(ball, completeCallback) {
    var self = this;
    this.isEnded = false;
    this.ball = ball;
    this.ball.on('animationend mozanimationend webkitAnimationEnd oAnimationEnd msanimationend', function () {
        self.isEnded = true;
        if (typeof completeCallback === 'function') {
            completeCallback();
        } 
    });
}
animation.prototype.nextStage = function () {
    this.ball.show().addClass('stage' + this.stage); //start the animation
    this.isEnded = false;
}


function main() {
    this.ball = new animation(DOM_ELEMENT, this.completeCallback);
}

main.prototype.completeCallback = function () {
   alert('ANIMATION IS DONE');
};

main.prototype.checkAnimation = function () {
    if (this.ball.isEnded) {
        //do stuff for something that is not part of animation items..
    }
}

当你想要动画时调用 this.ball.nextStage();

关于javascript - 如何检查我的 css 动画是否完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21489638/

相关文章:

javascript - 如何防止include bootstrap-combined.min.css 后表格样式改变?

php - 将 PHP 图片资源标识符转换为 html <img> 元素

javascript - 如果 <ul> 的长度超过屏幕宽度,则 <li> 元素转到下一行

javascript - 如果在新选项卡中打开,EmberJS 无法显示所有内容

javascript - 如何在 jsx 标签内写一个大于号?

javascript - 锁定同时 JavaScript 调用

jquery - 如果和如果不是如何结合

javascript - 如何添加到列表内的 onclick 函数,即<li onclick =""><button onclick =""></button></li>

javascript - 使用多个 css 时如何减少页面加载时间

javascript - 有没有办法在 DHTMLX 网格的每一行中添加编辑/删除按钮?