【发布时间】:2015-03-01 03:42:43
【问题描述】:
大家好,我想知道是否可以使用 jQuery 禁用垂直鼠标滚轮。我不能使用 CSS,因为我有需要可见的溢出
$("#ab").bind("mousewheel", function() { //only effect scrolling to the right??
return false;
});
谢谢
【问题讨论】:
大家好,我想知道是否可以使用 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();
}
})
});
【讨论】: