jQuery .animate()回调无限循环 [英] jQuery .animate() callback infinite loop
本文介绍了jQuery .animate()回调无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一个简单的问题:为什么我可以这样做
var start = function(){
$(' #element')。animate({},5000,'linear',start);
}
但不是这个
< pre $
function start(){
$('#element')。animate({},5000,'linear',start());
}
?
第一个完美的作品,完成后重新开始动画。第二种方法会导致无限循环。
解决方案
无论是使用
function start(){
$('#element')。animate({},5000,'linear',start);
}
或
function start(){
$('#element')。animate({},5000,'linear',function(){start();});
}
第二种情况很有用,如果您想实际传递一些参数开始..
A simple question: Why can I do this
var start = function() {
$('#element').animate({}, 5000, 'linear', start);
}
but not this
function start() {
$('#element').animate({}, 5000, 'linear', start());
}
?
The first works perfectly, restarting the animation after it completes. The second simply causes an infinite loop.
解决方案
Either use
function start() {
$('#element').animate({}, 5000, 'linear', start);
}
or
function start() {
$('#element').animate({}, 5000, 'linear', function(){ start(); });
}
second case is useful if you want to actually pass some arguments to start..
这篇关于jQuery .animate()回调无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文