javascript 删除鼠标滚轮滚动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15185111/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove mouse wheel scrolling
提问by kosnkov
I have a div with a height and overflow-x: hidden
so I can see the vertical scroll-bar.
Now when I scroll the whole page with the mouse wheel, if my cursor goes on the top of that div it starts scrolling the div instead of the page. Is it possible to remove mouse scrolling on this particular div?
我有一个高度的 div,overflow-x: hidden
所以我可以看到垂直滚动条。现在,当我用鼠标滚轮滚动整个页面时,如果我的光标位于该 div 的顶部,它会开始滚动 div 而不是页面。是否可以删除此特定 div 上的鼠标滚动?
回答by Dan Ovidiu Boncut
回答by Axel
The only way I can think you can achieve something similar to this is by capturing the mouseover event of that particular div and disable the wheel for the whole page, and enable it again on mouseout. In this post you can see how to disable the wheel for the whole page : How to disable scrolling temporarily?
我认为您可以实现与此类似的唯一方法是捕获该特定 div 的鼠标悬停事件并禁用整个页面的滚轮,然后在鼠标移出时再次启用它。在这篇文章中,您可以看到如何禁用整个页面的滚轮:如何暂时禁用滚动?
回答by Dai
No, because the user expects to be able to scroll a scrollable region with the mousewheel, and the user selects a scrollable region by moving the mouse pointer over it.
否,因为用户希望能够使用鼠标滚轮滚动可滚动区域,并且用户通过将鼠标指针移到可滚动区域上来选择该区域。
You can disable scrolling by setting overflow-y: hidden
but that will cause the scrollbars to disappear.
您可以通过设置禁用滚动,overflow-y: hidden
但这会导致滚动条消失。
回答by antonyh
I believe that you can add a handler to the
我相信你可以添加一个处理程序
onmousewheel
event to prevent it from scrolling (this is listed as HTML5 so might not work in older browsers). There's a full list of events here: http://www.w3schools.com/tags/ref_eventattributes.asp
事件以防止其滚动(这被列为 HTML5,因此可能无法在旧浏览器中使用)。这里有完整的活动列表:http: //www.w3schools.com/tags/ref_eventattributes.asp