一段时间后,jquery 超时在 chrome 中失败
所以我有这个脚本,它只是淡入淡出 p 标签并循环浏览它们。出于某种原因,如果我将页面打开一段时间,它们就会停止淡出并开始相互堆叠。这需要一段时间才能发生,我认为这只发生在 chrome 中。
$(document).ready(function(){
var current_quote = 0,
fade_interval = null,
num_quotes = $("#quotes p").length;
// Fade in the first quote.
$("#quote0").fadeIn(2500);
// Schedule for the inital fade out.
setTimeout(fadeQuotes, 6000);
function fadeQuotes() {
// Fade out the current quote.
$("#quote" + current_quote).fadeOut(2500, function() {
// Fade in the next quote.
current_quote = (current_quote + 1)
if(current_quote+1 > num_quotes)
{
current_quote=0;
}
current_quote = current_quote % num_quotes;
$("#quote" + current_quote).fadeIn(2500);
});
// Set the fading interval, if it's not already set.
if (fade_interval == null) {
fade_interval = setInterval(fadeQuotes, 13010);
}
}
});
so i have this script that is simply fading p tags in and out and cycling through them. For some reason if i leave the page open for awhile, they stop fading out and just start stacking on top of eachother. It takes awhile for it to happen and I think it only happens in chrome.
$(document).ready(function(){
var current_quote = 0,
fade_interval = null,
num_quotes = $("#quotes p").length;
// Fade in the first quote.
$("#quote0").fadeIn(2500);
// Schedule for the inital fade out.
setTimeout(fadeQuotes, 6000);
function fadeQuotes() {
// Fade out the current quote.
$("#quote" + current_quote).fadeOut(2500, function() {
// Fade in the next quote.
current_quote = (current_quote + 1)
if(current_quote+1 > num_quotes)
{
current_quote=0;
}
current_quote = current_quote % num_quotes;
$("#quote" + current_quote).fadeIn(2500);
});
// Set the fading interval, if it's not already set.
if (fade_interval == null) {
fade_interval = setInterval(fadeQuotes, 13010);
}
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当页面处于隐藏选项卡时,Chrome 将超时分钟设置为 1 秒。有点奇怪。
Chrome sets timeout min to 1 second when page is in hidden tab. It's a bit weird.
我不确定这是否是解决方案,但是代码中的一些冗余可能会导致问题。试试这个...
演示:http://jsfiddle.net/wdm954/beQxv/4/
I'm not sure if this is the solution however some redundancies in your code may be causing a problem. Try this out...
Demo: http://jsfiddle.net/wdm954/beQxv/4/