使用setInterval()函数闪烁图像 [英] Image flickering with setInterval() function
问题描述
我制作了一个轮播,并使用javascript setInterval()
函数在轮播中以固定间隔旋转图像.这是我用过的脚本
I have made a carousel and using javascript setInterval()
function for rotate image with fixed interval in carousel. Here's the script that i had used
var timeOut = 4000;
function showSlide() {
//....script for showing image
}
function pauseSlide() {
setInterval(function(){showSlide();}, timeOut);
}
jQuery(document).ready(function() {
pauseSlide();
});
现在的问题是,当我更改浏览器选项卡并在几分钟后再次返回轮播浏览器时,我看到轮播运行得比默认时间间隔快,而不是默认时间间隔,所以要快速更改图像的时间间隔应该设为0.请帮我如何解决这个问题.
Now the problem is when i have change the browser tab and after few minute back again to carousel browser and what i seen carousel running too faster rather than default time interval, images going to change fast suppose 0 time interval. Please help me how can i sort out this.
推荐答案
据我所知,在较新的firefox和chrome版本中,背景标签将setTimeout和setInterval固定为1000ms以提高性能.因此,我认为您的问题可能与此有关.
From what I know in newer versions of both firefox and chrome, background tabs have setTimeout and setInterval clamped to 1000ms to improve performance. So I think that your issue might relate to that.
也许这会有所帮助: 查看全文