我有2个按钮:“disable_scroll”和“enable_scroll”用于启用/禁用鼠标滚动。 禁用滚动效果很好:
var cancelscroll = function(e) {
e.preventDefault();
};
$("#disable_scroll").on("click", function () {
if ("onmousewheel" in document) { // for browser except FF
document.onmousewheel = cancelscroll;
} else { // for FF
document.addEventListener('DOMMouseScroll', cancelscroll);
}
});
但是当我想启用鼠标滚动时,我在Firefox中遇到了问题。在Firefox中,鼠标滚动不会打开(在其他浏览器中,此代码运行良好)。请任何人帮助找到错误吗?
$("#enable_scroll").on("click", function () {
if ("onmousewheel" in document) { // for brouzers except FF
document.onmousewheel = function(e){};
} else { // for FF
document.addEventListener('DOMMouseScroll', function(e){});
}
});
答案 0 :(得分:0)
这适用于所有地方:https://github.com/brandonaaron/jquery-mousewheel/blob/master/jquery.mousewheel.js
你这样使用它:
$('#test3')
.hover(function() { log('#test3: mouseover'); }, function() { log('#test3: mouseout'); })
.mousewheel(function(event, delta, deltaX, deltaY) {
log('#test3: I should not have been logged');
})
.unmousewheel();