如您所见,我有许多垂直排列的点!在向下滚动时,它起作用了,当向下滚动一个点时,它得到了一个改变球样式的类,我希望在向上滚动时发生完全相同的事情,但是它不起作用!请任何输入表示赞赏!这是一支电笔供您参考!在html,css和javascript下面:var activeMilestone = function() { var milestoneBalls = $('.dot'); milestoneBalls[0].classList.add("active"); window.onscroll = function() { milestoneBalls.each(function(i, v) { var thisBall = $(this); var nextBall = milestoneBalls[i + 1]; var prevBall = milestoneBalls[i - 1]; var thisPositionTop = thisBall.offset().top + ($(this).parent().height() / 3); var winScroll = window.scrollY; if (thisPositionTop <= winScroll) { nextBall.classList.add("active"); thisBall.addClass("inactive"); } if (thisPositionTop >= winScroll) { //this.classList.add("inactive_ball"); } }); }}$(document).ready(activeMilestone);.wrapper { height: 1000px; background-color: wheat;}.info_wrapper { margin-top: 70px;}.container { height: 50%; display: flex; flex-direction: column; justify-content: space-between; align-items: center;}.dot { width: 30px; height: 30px; border-radius: 20px; background-color: maroon; border: solid 4px green;}.active { border: solid 4px yellow; background-color: red;}.inactive { background-color: maroon; border: solid 4px green;}.text {}.header { width: 100%; height: 50px; background-color: lightblue;}
2 回答

慕妹3242003
TA贡献1824条经验 获得超6个赞
您可以在jQuery上使用转轮。
$(window).on('wheel',function(e) {
var mov = e.originalEvent.deltaY;
if(mov > 0) {
alert("up");
}else {
alert("down");
}
});
这样可以解决有关滚动方向检测的问题。
添加回答
举报
0/150
提交
取消