当我向下转动鼠标滚轮时,控制台中不断出现Uncaught ReferenceError: sectionScrollTimer is not defined。当用户转动鼠标滚轮时,代码应该会自动从div滚动到div。可能的问题是什么?
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 );
}
}
});
}发布于 2016-09-09 16:08:07
找到问题了:
var sectionScrollTimer = 0;在开始的时候。
https://stackoverflow.com/questions/39395559
复制相似问题