How do I suppress window mouse wheel scrolling...?
Asked Answered
C

2

8

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?!

Chive answered 5/12, 2008 at 9:13 Comment(0)
S
9

Attach 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!

Shoal answered 5/12, 2008 at 9:27 Comment(1)
and If the element is an iframe with needed scrollable content? what then? In that case this trick didn't work for me, doing this on the iframe object.Popliteal
H
0

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");
Haymaker answered 28/3, 2014 at 12:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.