admin管理员组文章数量:1355564
I'm working on a canvas app embedded in a page. I have it so you can zoom into the drawing with the mousewheel but unfortunately this scrolls the page as it is part of an article.
Is it possible to prevent mousewheel scrolling on the window when I'm mousewheeling on a dom element?!
I'm working on a canvas app embedded in a page. I have it so you can zoom into the drawing with the mousewheel but unfortunately this scrolls the page as it is part of an article.
Is it possible to prevent mousewheel scrolling on the window when I'm mousewheeling on a dom element?!
Share Improve this question asked Dec 5, 2008 at 9:13 JonJon2 Answers
Reset to default 9Attach an event handler for mousewheel (Not Gecko) / DOMMouseScroll (Not IE) and prevent its default action (that is to scroll content):
if (element.addEventListener) element.addEventListener("DOMMouseScroll", function(event) { event.preventDefault(); }, false); else element.attachEvent("mousewheel", function() { return false; })
Hope this helps!
I know this is old, but this may still be helpful to googlers.
I've written a jQuery plugin to handle this: $.disablescroll.
Not only does it handle mousewheels, but also touchmove and keypress events which would normally trigger a scroll.
// disable all scrolling:
$(window).disablescroll();
// enable scrolling again:
$(window).disablescroll("undo");
本文标签: javascriptHow do I suppress window mouse wheel scrollingStack Overflow
版权声明:本文标题:javascript - How do I suppress window mouse wheel scrolling...? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743942333a2565790.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论