2016-09-08 3 views
0

マウスホイールを下に動かすと、私はいつもコンソールにUncaught ReferenceError: sectionScrollTimer is not definedを取得します。ユーザーがマウスホイールを回すと、divは自動的にdivにスクロールします。何が問題なの?冒頭でセクションまでスクロールjQuery未捕捉参照エラー

var sectionScrollTimer = 0; 

if (jQuery('.dsd_section_to_scroll').length > 0) { 

    jQuery('.dsd_section_to_scroll').first().addClass('active'); 

    jQuery(document).on('wheel', function (e) { 
     if (jQuery(window).width() > 767) { 
     var delta = e.originalEvent.deltaY < 0 || e.originalEvent.wheelDelta > 0 ? 1 : -1; 
     var scrollSections = jQuery('.dsd_section_to_scroll'); 
     var indexToScroll = -1; 
     jQuery.each(scrollSections, function(index, item){ 
      if (jQuery(item).hasClass('active')){ 
       indexToScroll = index - delta; 
      } 
     }); 
     if (indexToScroll in scrollSections) { 
      e.preventDefault(); 
      clearTimeout(sectionScrollTimer); 
      sectionScrollTimer = setTimeout(function(){ 
       var next = jQuery(scrollSections[indexToScroll]); 
       jQuery('body, html').animate({ 
        scrollTop: next.offset().top 
       }, 'slow'); 

       jQuery('.dsd_section_to_scroll').removeClass('active'); 
       next.addClass('active'); 
      }, 250); 
     } 
     } 
    }); 
    } 
+0

あなたはプラグインを使用していますか? 'sectionScrollTimer ='はあるグローバルポイントで宣言されたvarでなければなりません。 – DaniP

+0

いいえ、ここからコードを取ったhttp://philips.thedemourl.com/wp-content/themes/philipsmobile-child/js/dsd_scripts.jsそしてプラグインを使用していません –

+0

最初の行はグローバル変数を定義しましたそれを含める? – DaniP

答えて

0

は、問題を発見しました。

関連する問題