我有以下结构:
<body>
<div id="first-div">
<div id="second-div"></div>
<div id="third-div"></div>
</div>
</body>
#first-div {
height: 100%;
}
#second-div, #third-div {
display: none;
}
在检测到第一个向下滚动事件后,我需要显示#second-div,如果检测到第二个向下滚动事件,我需要显示#third-div 并隐藏#second-div。我的问题是:触摸板上的单个向下滚动可能会触发多个事件,从而立即显示#second-div 和#third-div。
$(body).on('DOMMouseScroll mousewheel', function (event) {
if (event.originalEvent.detail > 0 || event.originalEvent.wheelDelta < 0) {
//scroll down
console.log('Down');
} else {
//scroll up
console.log('Up');
}
//prevent page fom scrolling
return false;
});
如何检测向下滚动事件、停止滚动事件并显示#second-div。然后检测另一个向下滚动事件,停止滚动事件并隐藏#second-div并显示#third-div?
另外,之后,我检测到向上滚动事件,停止滚动事件并隐藏#third-div 并显示#second-div。然后检测另一个向上滚动事件,停止滚动事件并隐藏#second-div?
谢谢你。