Javascript 在我的例子中,如何检查css动画是否完成?
我正在尝试检测我的css动画是否在我的应用程序中结束 我有如下的东西Javascript 在我的例子中,如何检查css动画是否完成?,javascript,jquery,html,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 msanimat
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()代码>当您想要设置动画时。这样,您可以在每次调用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()代码>当您想要设置动画时。这样,您可以在每次调用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()代码>当您想要设置动画时。这样,您可以在每次调用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()代码>当你想制作动画时。如果你在做一些异步的事情,你可以使用承诺或回调。这样传递回调可能对您有用:
animation.prototype.nextStage = function (callback) {
this.ball.show().addClass('stage' + this.stage); //start the animation
this.ball.on('animationend mozanimationend webkitAnimationEnd oAnimationEnd msanimationend', function () {
if (callback) callback();
})
}
main.prototype.checkAnimation = function () {
this.ball.nextStage(function () {
//do stuff for something that is not part of animation items..
});
}
这里有一个可能的承诺实现:
animation.prototype.nextStage = function () {
var def = $.Deferred();
this.ball.show().addClass('stage' + this.stage); //start the animation
this.ball.on('animationend mozanimationend webkitAnimationEnd oAnimationEnd msanimationend', function () {
def.resolve(true);
});
return def.promise();
}
main.prototype.checkAnimation = function () {
var promise = this.ball.nextStage();
promise.done(function () {
//do stuff for something that is not part of animation items..
});
}
如果您正在执行异步操作,那么可以使用承诺或回调。这样传递回调可能对您有用:
animation.prototype.nextStage = function (callback) {
this.ball.show().addClass('stage' + this.stage); //start the animation
this.ball.on('animationend mozanimationend webkitAnimationEnd oAnimationEnd msanimationend', function () {
if (callback) callback();
})
}
main.prototype.checkAnimation = function () {
this.ball.nextStage(function () {
//do stuff for something that is not part of animation items..
});
}
这里有一个可能的承诺实现:
animation.prototype.nextStage = function () {
var def = $.Deferred();
this.ball.show().addClass('stage' + this.stage); //start the animation
this.ball.on('animationend mozanimationend webkitAnimationEnd oAnimationEnd msanimationend', function () {
def.resolve(true);
});
return def.promise();
}
main.prototype.checkAnimation = function () {
var promise = this.ball.nextStage();
promise.done(function () {
//do stuff for something that is not part of animation items..
});
}
如果您正在执行异步操作,那么可以使用承诺或回调。这样传递回调可能对您有用:
animation.prototype.nextStage = function (callback) {
this.ball.show().addClass('stage' + this.stage); //start the animation
this.ball.on('animationend mozanimationend webkitAnimationEnd oAnimationEnd msanimationend', function () {
if (callback) callback();
})
}
main.prototype.checkAnimation = function () {
this.ball.nextStage(function () {
//do stuff for something that is not part of animation items..
});
}
这里有一个可能的承诺实现:
animation.prototype.nextStage = function () {
var def = $.Deferred();
this.ball.show().addClass('stage' + this.stage); //start the animation
this.ball.on('animationend mozanimationend webkitAnimationEnd oAnimationEnd msanimationend', function () {
def.resolve(true);
});
return def.promise();
}
main.prototype.checkAnimation = function () {
var promise = this.ball.nextStage();
promise.done(function () {
//do stuff for something that is not part of animation items..
});
}
如果您正在执行异步操作,那么可以使用承诺或回调。这样传递回调可能对您有用:
animation.prototype.nextStage = function (callback) {
this.ball.show().addClass('stage' + this.stage); //start the animation
this.ball.on('animationend mozanimationend webkitAnimationEnd oAnimationEnd msanimationend', function () {
if (callback) callback();
})
}
main.prototype.checkAnimation = function () {
this.ball.nextStage(function () {
//do stuff for something that is not part of animation items..
});
}
这里有一个可能的承诺实现:
animation.prototype.nextStage = function () {
var def = $.Deferred();
this.ball.show().addClass('stage' + this.stage); //start the animation
this.ball.on('animationend mozanimationend webkitAnimationEnd oAnimationEnd msanimationend', function () {
def.resolve(true);
});
return def.promise();
}
main.prototype.checkAnimation = function () {
var promise = this.ball.nextStage();
promise.done(function () {
//do stuff for something that is not part of animation items..
});
}
您是否尝试过承诺或回调?动画完成后执行animation.prototype.isEnded
。你是否尝试过承诺或回调?动画完成后执行animation.prototype.isEnded
。你是否尝试过承诺或回调?动画完成后执行animation.prototype.isEnded
。你是否尝试过承诺或回调?动画完成后执行animation.prototype.isEnded
。也许可以给它起个更有意义的名字。谢谢你的提示,但是,动画需要时间来播放,而这个.ball.isEnded总是为false。要达到self.isEnded=true,我不知道如何设置它+1您可以添加回调。请查看我答案中的更改。感谢您的提示,但是,动画需要时间来播放,而this.ball.isEnded始终为false。要达到self.isEnded=true,我不知道如何设置它+1您可以添加回调。请查看我答案中的更改。感谢您的提示,但是,动画需要时间来播放,而this.ball.isEnded始终为false。要达到self.isEnded=true,我不知道如何设置它+1您可以添加回调。请查看我答案中的更改。感谢您的提示,但是,动画需要时间来播放,而this.ball.isEnded始终为false。要达到self.isEnded=true,我不知道如何设置它+1您可以添加回调。看看我答案中的变化。