在 iframe 上检测鼠标移动? [英] Detect mousemove when over an iframe?
问题描述
我有一个占据整个窗口(100% 宽,100% 高)的 iframe,我需要主窗口能够检测到鼠标何时被移动.
I have an iframe that takes up the entire window (100% wide, 100% high), and I need the main window to be able to detect when the mouse has been moved.
已经在 iframe 上尝试了 onMouseMove
属性,但显然没有用.还尝试将 iframe 包装在一个 div 中,如下所示:
Already tried an onMouseMove
attribute on the iframe and it obviously didn't work. Also tried wrapping the iframe in a div like so:
<div onmousemove="alert('justfortesting');"><iframe src="foo.bar"></iframe></div>
......它没有用.有什么建议吗?
.. and it didn't work. Any suggestions?
推荐答案
如果您的目标不是 Opera 9 或更低版本和 IE 9 或更低版本,您可以使用 css 属性 pointer-events: none
.
If your target isn't Opera 9 or lower and IE 9 or lower you can use css attribute pointer-events: none
.
我发现这是忽略 iframe 的最佳方式.我在 onMouseDown
事件中将具有此属性的类添加到 iframe 并在 onMouseUp
事件中删除.
I found it the best way just to ignore iframe. I add class with this attribute to iframe in onMouseDown
event and remove in onMouseUp
event.
非常适合我.
这篇关于在 iframe 上检测鼠标移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!