在 iframe 上检测鼠标移动? [英] Detect mousemove when over an iframe?

查看:18
本文介绍了在 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屋!

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