来自另一个选项卡时,jquery setInterval速度太快 [英] Jquery setInterval too fast when coming from another tab

查看:363
本文介绍了来自另一个选项卡时,jquery setInterval速度太快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在Chrome 13中调用页面时,我切换到另一个选项卡以进入几秒钟后,图像滑动发生得更快,好像它试图保持原来的位置,如果它没有切换到另一个标签。



怎么可能我解决了这个问题吗?

$ $ $ $ $($) ;
});

function nextSlide(){
offset + = delta;
$(#slideContent)。animate({left:-1 * offset},1000);
}

解决方案:

我选择了jfriend00的第一条建议。现在,当窗口变为非活动状态时,我关闭定时器。

简单的代码可以找到 here

在开始时,我想为所有的错误道歉 - 我的英语不完美。



您的问题的解决方案可能非常简单:

  $(window).load(function(){
setInterval(nextSlide,3500);
});

function nextSlide(){
offset + = delta;
$(#slideContent)。stop(true,true).animate({left:-1 * offset},1000);
}

不活动的浏览器选项卡缓冲一些setInterval或setTimeout函数。
stop(true,true) - 将停止所有缓冲事件并仅执行最后一次动画。
此问题也将出现在Firefox> 5.0 - 阅读本文: Firefox 5 - 更改 b
$ b


window.setTimeout()方法现在可以在非活动状态下每秒发送不超过一个
的超时值标签。此外,它现在将嵌套的
超时限制为HTML5规范允许的最小值:4
ms(而不是10 ms用于限制)。

在这里您可以阅读,animate如何工作 - 它会多次触发setInterval函数。 动画效果如何在jQuery中工作


I've got a site with endlessly sliding images using jquery's setIntervall() function.

When calling the page in Chrome 13 and I switch to another tab to come back a few seconds later the image sliding is happening faster, as if it tried to keep up to where it was if it hadn't switched to another tab.

How could I resolve this issue?

$(window).load(function() { 
    setInterval(nextSlide, 3500);
});

function nextSlide(){   
    offset += delta;
    $("#slideContent").animate({left: -1 * offset}, 1000);
}

Solution:

I chose jfriend00's first advise. Now I turn the timer off when the window becomes inactive.

The simple code to do so can be found here.

解决方案

At the beginning I would like to apologize for all the mistakes - my English is not perfect.

The solution of your problem may be very simple:

$(window).load(function() { 
    setInterval(nextSlide, 3500);
});

function nextSlide(){   
    offset += delta;
    $("#slideContent").stop(true,true).animate({left: -1 * offset}, 1000);
}

inactive browser tabs buffer some of the setInterval or setTimeout functions. stop(true,true) - will stop all buffered events and execute immadietly only last animation. This problem will also appears in Firefox > 5.0 - read this article: Firefox 5 - changes

The window.setTimeout() method now clamps to send no more than one timeout per second in inactive tabs. In addition, it now clamps nested timeouts to the smallest value allowed by the HTML5 specification: 4 ms (instead of the 10 ms it used to clamp to).

here you can read, how animate works - it fires setInterval function many times. How animate really works in jQuery

这篇关于来自另一个选项卡时,jquery setInterval速度太快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆