如何抑制窗口鼠标滚轮滚动...? [英] How do I suppress window mouse wheel scrolling...?

查看:92
本文介绍了如何抑制窗口鼠标滚轮滚动...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

希望这会有所帮助!

这篇关于如何抑制窗口鼠标滚轮滚动...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆