我有几列 Logo ,我想运行一个函数来为每一列的 Logo 设置动画,但不是同时运行,我想在函数为每一列运行的时间之间有一个延迟。这是我的代码:
var startRotation = function() {
$( ".ticker" ).each( function( index, element ){
myInterval = setTimeout(function() {
otherInterval = setInterval(function(){
slideImageUp(element); //runs function to animate
}, 3000);
}, 1000 * index);
});
};
问题是在我在浏览器上切换选项卡后 setTimeout 重置,最终所有列同时动画。我也尝试了几乎所有我在这里找到的解决方案,但似乎无法找到一种方法让它发挥作用。我已经研究了一段时间,我认为解决方案可能很简单,但我就是看不到。谢谢。
最佳答案
换一种方式就好了。每 3 秒,在适当的时间为所有 Logo 设置超时。
var startRotation = function() {
otherInterval = setInterval(function(){
$( ".ticker" ).each( function( index, element ){
myInterval = setTimeout(function() {
slideImageUp(element); //runs function to animate
}, 1000 * index);
});
}, 3000);
};
关于javascript - 切换选项卡后丢失 setTimeout 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34055202/