【发布时间】:2011-08-09 10:37:00
【问题描述】:
为了摆脱在标签(窗口)不活动(失去焦点)期间由setTimeout(或setInterval)引起的动画堆积,我不得不使用递归回调,例如:
function auto() {
interval = setTimeout(function() {
$('#slider').animate({left: '-=500'}, 800, function(){
auto(); // THE RECURSIVE CALLBACK
});
}, 2000);
}
auto();
现在我希望 不 重用 #slider 的 动画 本身,因为我已经在之前的 function animate() 中定义了它(不更改function animate 因为我必须在其他地方使用它,就像它一样):
function animate(){
$('#slider').animate({left: '-=500'}, 800);
}
如何获得这样的工作:
function auto() {
interval = setTimeout(function() {
animation();auto(); // THIS IS WRONG AS NOT a RECURSIVE CALLBACK - and creates animation buildup
}, 2000);
}
auto();
提前非常感谢!
【问题讨论】:
标签: jquery function settimeout