移动 var sum = 0 超出触发功能。它在您的实现中的每个滚动上设置为零:
var sum = 0
var sum = 0; $(window).on('wheel', function(e) { var delta = e.originalEvent.deltaY; if (delta > 0){ sum++; console.log("going down"); console.log(sum); } else { if (sum > 0) { sum--; } console.log("going up"); console.log(sum); } return false; });
html, body{ height: 100%; } #firstbox{ background: red; } #second_box{ background: blue; } #third_box{ background: black; } .general{ width: 100%; height: 100%; } header{ width: 100%; height: 100%; } img{ width: 100%; height: 100%; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="firstbox" class="general"> <header><img src="https://cdn.pixabay.com/photo/2017/06/05/20/10/blue-2375119_960_720.jpg" alt="image here"></header> </div> <div id="second_box" class="general"> </div> <div id="third_box" class="general"> </div>