首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >滚动到部分jQuery未捕获引用错误

滚动到部分jQuery未捕获引用错误
EN

Stack Overflow用户
提问于 2016-09-09 00:01:34
回答 1查看 228关注 0票数 0

当我向下转动鼠标滚轮时,控制台中不断出现Uncaught ReferenceError: sectionScrollTimer is not defined。当用户转动鼠标滚轮时,代码应该会自动从div滚动到div。可能的问题是什么?

代码语言:javascript
复制
  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 );
        }
      }
    });
  }
EN

回答 1

Stack Overflow用户

发布于 2016-09-09 16:08:07

找到问题了:

代码语言:javascript
复制
var sectionScrollTimer = 0;

在开始的时候。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39395559

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档