我在函数内部有一个动画。我如何编码以便在离开函数之前动画应该先完成?jquery在离开函数之前等待动画完成
考虑下面的代码:
ShowBanner.prototype.basicRotate = function (pos, callback) {
var self = this;
self.animation = true;
this.bigbannerScroll.animate({
left: pos
}, this.settings.rotateSpeed, function() {
self.animation = false;
if (callback) callback();
console.log('animation done');
return false;
});
console.log('function done');
}
基于代码的console.log('function done')
是console.log('animation done')
之前首先调用。有没有办法让第一个日志先被调用,说明离开函数之前动画已经完成了?
它不会这样工作,因为animate是一个异步函数,您需要使用回调机制 – 2013-04-24 08:52:59