好的,现在解释时间.. :) 假设 1 div 有 100% 的页面封面,当我向下滚动时,第二个 div 立即占据它的位置,并且与第三个相同。我认为这个问题的答案很长,但这对我以及其他寻找这个答案的人都会很有帮助。提前致谢
问问题
59 次
1 回答
2
在此示例中,页面使用鼠标滚轮执行您想要的操作。您可能想要添加对滚动条和键盘 uo/向下箭头等的支持。这是来自Vaibs_Cool
$(document.body).on('DOMMouseScroll mousewheel', function (e) {
if (e.originalEvent.detail > 0 || e.originalEvent.wheelDelta < 0) {
dir = 'down';
} else {
dir = 'up';
}
// find currently visible div :
div = -1;
divs.each(function(i){
if (div<0 && ($(this).offset().top >= $(window).scrollTop())) {
div = i;
}
});
if (dir == 'up' && div > 0) {
div--;
}
if (dir == 'down' && div < divs.length) {
div++;
}
//console.log(div, dir, divs.length);
$('html,body').stop().animate({
scrollTop: divs.eq(div).offset().top
}, 200);
return false;
});
于 2013-10-12T04:41:09.750 回答