jquery .animate()和.done()

我试图在动画完成后启动一个函数,但我无法使它工作。

这是我的代码:

var count = 3; var timer = setInterval(function () { handleTimer(count); }, 1000); function endCountdown() { $('.begin-btn').html("GO!"); } function handleTimer() { if (count === 0) { clearInterval(timer); endCountdown(); } else { $('.begin-btn').html(count); count--; } } $('.begin-mrsuper').delay(500).animate({ "left": "4px" }, "slow").promise().done(function (handleTimer) {}); 

我尝试过:

  $('.begin-mrsuper').delay(500).animate({"left":"4px"}, "slow").promise().done(function(){ handleTimer(); }); 

但是3,2,1,GO计时器在动画结束之前就开始了,任何想法?

setInterval部分包装到一个函数中,或者在调用它后执行它。

 var count = 3, timer = null; var foo = function() { timer = setInterval(function () { handleTimer(count); }, 1000); }; function endCountdown() { $('.begin-btn').html("GO!"); } function handleTimer() { if (count === 0) { clearInterval(timer); endCountdown(); } else { $('.begin-btn').html(count); count--; } } $('.begin-mrsuper').delay(500).animate({ "left": "4px" }, "slow").promise().done(foo); 

像这样的东西可能会起作用:

 $('.begin-mrsuper').delay(500).animate({ "left": "4px" }, "slow", function(){ handleTimer(); }).promise();