应该是一个很简单的问题。我希望这个 jQuery 动画在 1 个循环后停止运行,而不是无限循环。
这绝对是简单的事情,但这是我不久前得到帮助的代码,我一生都无法弄清楚它为什么循环。
谢谢。
jsFiddle: http://jsfiddle.net/SFejj/和代码:
function move(jElem, bUp, iSpeed) {
jElem.animate(
{
opacity: (bUp ? '+' : '-') + '0.1',
width: (bUp ? '+' : '-') + '=200',
height: (bUp ? '+' : '-') + '=200'},
iSpeed,
function() {
move(jElem, !bUp, iSpeed);
}
);
}
$(document).ready(function() {
$('.navImage').each(function(iIndex, jElem) {
// get random delay
var iTime = Math.floor(Math.random() * 1000);
// get random speed
var iSpeed = Math.floor(Math.random() * 1000) + 1500;
setTimeout(
function() {
move($(jElem), true, iSpeed);
},
iTime
);
});
});
最佳答案
移动函数递归调用移动函数。导致堆栈溢出的好方法!
关于jquery - 防止 jQuery 中的无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8170683/