如何使用 Javascript 从鼠标悬停事件中排除元素?
我基本上是在尝试在浏览器中构建相当于 firebug 检查器的东西。在本例中,我当前使用 作为容器:
container.onmouseover = function(ev) { inspect(ev.target); }
在检查方法中,我在从事件目标返回的元素上重新定位半透明固定定位元素并调整其大小。但这会导致 mouseover
事件随后检查覆盖元素本身。
我基本上希望事件处理程序完全忽略覆盖的元素(它的存在只是为了提供视觉反馈)并继续为在其下方检测到的元素触发 onmouseover
事件。这有道理吗?
I'm basically trying to build the equivalent of the firebug inspector in the browser. I'm currently using the <body>
as the container in this example:
container.onmouseover = function(ev) { inspect(ev.target); }
In the inspect method, I reposition and resize a semi-transparent fixed positioned element over the element returned from the event target. But this causes the mouseover
event to subsequently inspect the overlay element itself.
I basically want the event handler to disregard the overlaid element completely (it only exists to provide visual feedback) and continue to fire onmouseover
events for the elements detected beneath it. Does this make sense?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不必支持所有浏览器,那么您可以使用 css 属性 pointer-events< /a>.当设置为 none 时,所有事件都将被忽略。尝试在这个小提琴中切换指针事件,看看我的意思。
http://jsfiddle.net/zDygA/
浏览器支持
我不想链接出来,但如果您需要支持 IE,这是一篇好文章。
http://www.vinylfox.com/forwarding-mouse-events-through-层/
If you don't have to support all browsers then you could use the css property pointer-events. When set to none all events will be ignored. Try toggling pointer-events in this fiddle and see what I mean.
http://jsfiddle.net/zDygA/
Browser support
I hate to link out, but this is a good article if you need to support IE.
http://www.vinylfox.com/forwarding-mouse-events-through-layers/