2012-02-26 69 views
0

可能重复:
How can I make setInterval also work when a tab is inactive in Chrome?的setInterval跳跃时的浏览器选项卡之间移动

http://www.datingjapan.co

我的setInterval改变图片如下:

var initialFadeIn = 1000;   //initial fade-in time (in milliseconds) 
    var itemInterval = 6000;   //interval between items (in milliseconds) 
    var fadeTime = 2500;     //cross-fade time (in milliseconds) 

    var infiniteLoop = setInterval(function(){ 
     position1.eq(currentItem1).fadeOut(fadeTime); 
     if(currentItem1 == numberOfItems1 -1) {currentItem1 = 0;}else{currentItem1++;} 
     position1.eq(currentItem1).fadeIn(fadeTime); 
    }, itemInterval); 

我注意到,当我在Chrome中的浏览器标签之间移动时,当我回到站点时(间隔已过),图像快速跳转到下一个。是否有可能使这个更平滑?或让这发生在后台?

这方面的任何信息都会很棒。

THX

+0

这是在回答:http://stackoverflow.com/questions/5927284/how-can-i-make-setinterval-also-work-when-a-tab -is-inactive-in-chrome我不确定如何链接到特定的帖子,但搜索链接:http://jsfiddle.net/7f6DX/31/你也可以去那个链接对于一个可行的方法。 – conrad10781 2012-02-26 03:31:12

回答

0

它发生在使用setInterval但与setTimeout的。窍门是使用递归函数而不是setInterval。调用函数作为最后动画的回调

function infiniteLoop() { 
    setTimeout(function() { 
     position1.eq(currentItem1).fadeOut(fadeTime); 
     if (currentItem1 == numberOfItems1 - 1) { 
      currentItem1 = 0; 
     } else { 
      currentItem1++; 
     } 
     position1.eq(currentItem1).fadeIn(fadeTime, infiniteLoop); 
    }, itemInterval); 
} 

infiniteLoop(); 
相关问题