是否可以使用 jQuery 仅禁用鼠标滚轮向右滚动
Is it possible to disable only mouse wheel scrolling to the right using jQuery
大家好,我想知道是否可以使用 jQuery 禁用垂直鼠标滚轮。我不能使用 CSS 因为我有溢出需要可见
$("#ab").bind("mousewheel", function() { //only effect scrolling to the right??
return false;
});
谢谢
可能重复?直接从这里复制:Disabling vertical scroll by mouse
$('#ab')
.bind('mousewheel DOMMouseScroll', function(e) {
e.preventDefault();
});
或此处的另一个:How to do a horizontal scroll on mouse wheel scroll?
var mouseWheelEvt = function (event) {
if (document.body.doScroll)
document.body.doScroll(event.wheelDelta>0?"left":"right");
else if ((event.wheelDelta || event.detail) > 0)
document.body.scrollLeft -= 10;
else
document.body.scrollLeft += 10;
return false;
}
document.body.addEventListener("mousewheel", mouseWheelEvt);
更新:我认为这正是您要查找的代码:
$('#ab').bind('mousewheel DOMMouseScroll', function(e) {
// Replace with != 0 if you want to prevent left/right instead.
if (e.originalEvent.wheelDeltaX == 0) {
e.preventDefault();
}
});
你可以通过这种方式试试....
HTML--
<div id='no_scroll'></div>
CSS--
body {
height: 2000px;
}
#no_scroll{
width: 50px;
height: 1500px;
background: blue;
}
jQuery--
$(document).ready(function(){
$('body').on({
'mousewheel': function(e) {
if (e.target.id == 'no_scroll') return;
e.preventDefault();
e.stopPropagation();
}
})
});
大家好,我想知道是否可以使用 jQuery 禁用垂直鼠标滚轮。我不能使用 CSS 因为我有溢出需要可见
$("#ab").bind("mousewheel", function() { //only effect scrolling to the right??
return false;
});
谢谢
可能重复?直接从这里复制:Disabling vertical scroll by mouse
$('#ab')
.bind('mousewheel DOMMouseScroll', function(e) {
e.preventDefault();
});
或此处的另一个:How to do a horizontal scroll on mouse wheel scroll?
var mouseWheelEvt = function (event) {
if (document.body.doScroll)
document.body.doScroll(event.wheelDelta>0?"left":"right");
else if ((event.wheelDelta || event.detail) > 0)
document.body.scrollLeft -= 10;
else
document.body.scrollLeft += 10;
return false;
}
document.body.addEventListener("mousewheel", mouseWheelEvt);
更新:我认为这正是您要查找的代码:
$('#ab').bind('mousewheel DOMMouseScroll', function(e) {
// Replace with != 0 if you want to prevent left/right instead.
if (e.originalEvent.wheelDeltaX == 0) {
e.preventDefault();
}
});
你可以通过这种方式试试....
HTML--
<div id='no_scroll'></div>
CSS--
body {
height: 2000px;
}
#no_scroll{
width: 50px;
height: 1500px;
background: blue;
}
jQuery--
$(document).ready(function(){
$('body').on({
'mousewheel': function(e) {
if (e.target.id == 'no_scroll') return;
e.preventDefault();
e.stopPropagation();
}
})
});