【发布时间】:2013-10-31 00:57:19
【问题描述】:
我正在使用fullPage.js JQuery 插件(参见演示here)。该插件定义了全窗口大小的部分,并在用户向上或向下滚动时从“幻灯片”部分滚动到“幻灯片”。
我正在尝试修改它,以便滚动事件不会在滚动开始时立即触发,而是在短时间内或一定滚动量后触发,以防止用户意外滑动几个像素,这将触发滚动事件并滚动到下一张幻灯片。
例如,如果用户滚动偏移 100px,则滚动到下一张幻灯片。
Here 是fullpage.js 代码。我认为我将不得不修改此功能以获得我想要的:
//when scrolling...
$(window).scroll(function(e){
if(!options.autoScrolling){
var currentScroll = $(window).scrollTop();
var scrolledSections = $('.section').map(function(){
if ($(this).offset().top < (currentScroll + 100)){
return $(this);
}
});
//geting the last one, the current one on the screen
var currentSection = scrolledSections[scrolledSections.length-1];
//executing only once the first time we reach the section
if(!currentSection.hasClass('active')){
var yMovement = getYmovement(currentSection);
$('.section.active').removeClass('active');
currentSection.addClass('active');
var anchorLink = currentSection.data('anchor');
$.isFunction( options.onLeave ) && options.onLeave.call( this, currentSection.index('.section'), yMovement);
$.isFunction( options.afterLoad ) && options.afterLoad.call( this, anchorLink, (currentSection.index('.section') + 1));
activateMenuElement(anchorLink);
}
}
});
但我真的不知道该怎么做... 我想我可能应该在滚动开始和滚动结束时获取滚动偏移量/时间,获取差异,然后根据差异滚动到当前或下一张幻灯片,但我不知道如何在此函数中实现这一点以及如何获取滚动结束事件。
而且我不确定是否使用“滚动结束事件”,因为如果用户想要向下或向上滚动,脚本不应该等待用户停止滚动以滚动到它必须滚动的位置..
也许我应该在滚动过程中获得滚动偏移量,当偏移量 > x 时滚动到下一个,如果滚动停止并且偏移量
【问题讨论】:
标签: javascript jquery jquery-plugins scroll fullpage.js