我正在使用wheelDelta 检查滚动方向,但它一次返回大量滚动属性。我只需要知道它是上升还是下降,并且在第一次触发后它不应该返回低于 500 毫秒的值。我尝试使用 setTimeout 但无法很好地解决它。有什么想法吗?
var distance = $('.section-two').offset().top,
$window = $(window);
$window.scroll(function() {
if ( $window.scrollTop() >= distance ) {
$('body').css('overflow', 'hidden');
setTimeout(function(){
$(document).bind('mousewheel', function(evt) {
var delta = evt.originalEvent.wheelDelta;
if(delta > 0){
console.log('scrolled up')
} else {
console.log('scrolled down');
}
})
}, 500);
}
});
最佳答案
您能否在绑定(bind)'mousewheel'
事件之前尝试取消绑定(bind)它。看起来,它一次又一次地束缚着它。在 $(document).bind('mousewheel', function(evt) {
行之前添加 $(document).unbind('mousewheel');
。
关于javascript - jQuery 函数 - 防止返回 "for a while",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43837585/