IE 将 mousemove 绑定到 body
我正在尝试将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不希望它出现在正文中,因为正文不一定是整页。
jsfiddle: http://jsfiddle.net/uDfPj/
或者不使用 jQuery:
You don't want it in the body because body is not necessarily the full page.
jsfiddle: http://jsfiddle.net/uDfPj/
Alternatively without jQuery:
我怀疑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.
请尝试使用该文档。这是一个很棒的示例页面,显示它的工作原理
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