IE 将 mousemove 绑定到 body

发布于 2024-12-14 06:13:35 字数 535 浏览 3 评论 0原文

我正在尝试将 mousemove 事件绑定到主体。到目前为止我的尝试:

$('html, body').mousemove(function(event){...});

$('html, body')[0].onmousemove= function(event){...};

$('body').bind('mousemove', function(event){...});

document.onmousemove = function(event){...};

document.getElementsByTagName('body')[0].onmousemove = function(event){...};

编辑:

window.onmousemove = function(event){...}; // doesn't work either

编辑2:我需要整个身体响应,而不仅仅是嵌套元素。

所有这些都有效,但在 IE 中都不起作用。

我该如何解决这个问题?

I am trying to bind a mousemove event to the body. My attempts so far:

$('html, body').mousemove(function(event){...});

$('html, body')[0].onmousemove= function(event){...};

$('body').bind('mousemove', function(event){...});

document.onmousemove = function(event){...};

document.getElementsByTagName('body')[0].onmousemove = function(event){...};

EDIT:

window.onmousemove = function(event){...}; // doesn't work either

EDIT2: I need the whole body to be responsive, and not only nested elements.

All of these worked, but none did in IE.

How can I solve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

多孤肩上扛 2024-12-21 06:13:35

您不希望它出现在正文中,因为正文不一定是整页。

$( document ).mousemove( function () {

});

jsfiddle: http://jsfiddle.net/uDfPj/

或者不使用 jQuery:

document.documentElement.onmousemove = function(){};

You don't want it in the body because body is not necessarily the full page.

$( document ).mousemove( function () {

});

jsfiddle: http://jsfiddle.net/uDfPj/

Alternatively without jQuery:

document.documentElement.onmousemove = function(){};
情域 2024-12-21 06:13:35

我怀疑onMouseMove事件是否与body标签相关联。你能在窗口标签上试试吗?不过我还没有尝试过。

I doubt whether the onMouseMove event is associated with the body tag. Can you try it on the window tag? I haven't tried that though.

世界等同你 2024-12-21 06:13:35

请尝试使用该文档。这是一个很棒的示例页面,显示它的工作原理

http://www.quirksmode.org/ dom/events/tests/mousemove.html

和兼容性表:
http://www.quirksmode.org/dom/events/mousemove.html

try it with the document instead. here's a great sample page that shows it working

http://www.quirksmode.org/dom/events/tests/mousemove.html

and a compatibility table:
http://www.quirksmode.org/dom/events/mousemove.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文