0

我有一个 jquery 代码,它连续上下移动一个 div,其中包含一个带有徽标的列表。动画在设定的时间间隔内重复,并且在 Chrome、FireFox 和 IE 9 和 8 中似乎都按预期工作(没有控制台错误)。

但是在 IE7 中,我收到“脚本错误”并且浏览器完全冻结...我认为 setInterval 和 clearInterval 无法正常工作,或者我搞砸了我的代码...

这里是:

//<!------------------LOGOS ------------------>

// the automatic scroll start immediately
$(document).ready(function () { membersLogos() });

// set the interval after which to restart the animated scroll
$(function () {

  var intervalID;
  var resetTimer = function () {
    if (intervalID) { clearInterval(intervalID) };
    intervalID = setInterval(function () {
        membersLogos();
    }, 190000);
  };

});

// set the interval after which to restart the animated scroll

function membersLogos() {
  var pane = $('#mypane');

  if ($('#mypane').length) {
    pane.jScrollPane({
        animateScroll: true, //added
        animateDuration: 95000, //added - length each way in milliseconds
        stickToTop: true,
        //autoReinitialise: true,
        enableKeyboardNavigation: true
    });

    var api = pane.data('jsp');
    var logosHeight = parseInt($('#mypane .jspPane').height());

    //listen to the x-axis scrolling event
    pane.bind('jsp-scroll-y', function (event, pos_y, at_top, at_bottom) {
        //we're at the bottom now lets scroll back to the top
        if (at_bottom) {
            api.scrollToY(0);
            $(this).unbind(event); //added with edit
            $(this).bind('jsp-scroll-y', function (event, pos_y, at_top, at_bottom) {
                if (at_top) {
                    $(this).unbind(event);
                    api.scrollToY(logosHeight);
                }

            });

        }

    });

    //initial animate scroll to the top
    api.scrollToY(logosHeight);
  }
}

有什么想法或建议有什么问题吗?提前致谢!维克

4

1 回答 1

1

由于您已将间隔设置为两个动画的总和( 190000 = 95000 * 2),因此如果在动画完成之前再次触发间隔函数,我不会感到惊讶,可能会导致某些东西踩到其他东西. 很容易检查:只需将间隔设置为 300000 或其他值,看看问题是否消失。

为了避免间隔过早再次触发的可能性,而不是使用setInterval(这几乎总是比它的价值更麻烦),我会看看jScrollPane动画完成时是否为您提供完成回调。如果是,则使用该完成回调来触发下一个动画。如果没有,我可能会考虑添加它。

于 2011-12-01T12:13:25.537 回答