質問

ロゴのあるリストを含むDIVを継続的に上下に移動しているjQueryコードがあります。アニメーションはセット間隔内で繰り返されており、すべてが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);
  }
}

何が悪いのかというアイデアや提案はありますか?前もって感謝します! VIK

役に立ちましたか?

解決

間隔を設定しているので まさに 2つのアニメーション(190000 = 95000 * 2)の合計で、アニメーションが完了する前にインターバル関数が再び発射されていても、おそらく何か他のものに何かを踏むことになります。簡単に確認できます。間隔を300000などに設定して、問題がなくなるかどうかを確認してください。

使用するのではなく、間隔発火をすぐに再び発生させる可能性を避けるため setInterval (これはほとんど常にそれが価値があるよりも多くのトラブルです)、私は jScrollPane アニメーションが完了したときに完了コールバックを提供します。もしそうなら、その完了コールバックを使用して、次のアニメーションをトリガーします。そうでない場合は、おそらく追加しようとしています。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top