我正在尝试创建这种行为:当用户滚动鼠标滚轮(或按下↓</kbd>) the webpage is scrolled down by the height of the window.
我最终得到了以下代码:
var newScrollTop,
oldScrollTop = $(window).scrollTop(),
preventScroll = false;
$(window).scroll(function() {
if (!preventScroll) {
preventScroll = true;
newScrollTop = $(this).scrollTop();
if (newScrollTop > oldScrollTop) {
$(this).scrollTop( oldScrollTop + $(window).height() );
}
else {
$(this).scrollTop( oldScrollTop - $(window).height() );
}
oldScrollTop = newScrollTop;
preventScroll = false;
}
});
但这并不像我预期的那样工作:在滚动事件页面上滚动到最边缘(底部或顶部)。我错过了什么?