如何抑制窗口鼠标滚轮滚动...?

问题描述:

我正在使用嵌入页面的画布应用程序。我有它所以你可以使用鼠标滚轮放大绘图但不幸的是,它滚动页面,因为它是文章的一部分。

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.

是否可以防止鼠标滚轮滚动当我在dom元素上鼠标移动时的窗口?!

Is it possible to prevent mousewheel scrolling on the window when I'm mousewheeling on a dom element?!

附加鼠标轮的事件处理程序(Not Gecko)/ DOMMouseScroll (不是IE)并阻止其默认操作(即滚动内容):

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;
    })

希望这会有所帮助!