javascript - 自定义 Div slider 速度太快,但仅限于从另一个浏览器选项卡返回时

标签 javascript jquery jquery-animate browser-tab

当我查看正在运行的代码时,没有任何问题。但是,当我在另一个浏览器选项卡上花费一些时间,然后返回到正在运行的代码时,时间/速度太快了。

这是 jQuery:

var divId = 1;
var lp = 0;

$(document).ready(function (){

    setInterval(function()
        {
        //<![CDATA[

            if(divId < 6)
            {
                $('.main-banner').animate({ left: lp },400);

                $(".first-icon-inner").removeClass("active-icon");
                $("#banner-"+divId+" div:first").addClass('active-icon');

                    divId++;
                    lp-=550;

            }
            else
            {
                lp = 0;
                divId=1;

                $('.main-banner').animate({ left: lp },400);

                $(".first-icon-inner").removeClass("active-icon");
                $("#banner-"+divId+" div:first").addClass('active-icon');


            }
            //]]>

    }, 3400);

});

最佳答案

jQuery < 1.6.3 有一个错误...摘自 jQuery 1.6.3 release notes :

We had high hopes for the browser’s requestAnimationFrame API when we added support into version 1.6. However, one of the highest-volume complaints we’ve received since then relates to the way requestAnimationFrame acts when a tab is not visible. All the animations initiated when the tab is invisible “stack” and are not executed until the tab is brought back into focus. Then they all animate at warp speed! We’ve removed support for this API (which has no impact on the way you call jQuery’s animation features) and plan to incorporate it into a future version of jQuery.

我建议您更新到更新的版本...即 jQuery => 1.6.3

关于javascript - 自定义 Div slider 速度太快,但仅限于从另一个浏览器选项卡返回时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11501292/

相关文章:

javascript - 如何使图像(div)在网站内跟随光标?

javascript - 检测输入值

javascript - 绝对定位 div 的 100% 高度

javascript - 从 HTML 表单上传 3 张图片。通过 Javascript 将图像发送到 PHP 以上传

javascript - 使用 Knockout 将项目添加到列表后更改背景颜色

jquery - 隔离 jQuery FF4 问题

ios - 动画字符串(逐个字符)在动画期间不会出现在 UITextView 上

javascript - 如何在一些不同元素之间切换类?

Javascript while 循环使页面无法加载

javascript - 如何为 Google Places API 自动完成文本框设置默认值