[英]How can I exclude an element from a mouseover event with Javascript?
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:我目前在此示例中使用<body>
作为容器:
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.但这会导致mouseover
事件随后检查覆盖元素本身。
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.我基本上希望事件处理程序完全忽略覆盖的元素(它只是为了提供视觉反馈而存在)并继续为在其下方检测到的元素触发onmouseover
事件。 Does this make sense?这有意义吗?
If you don't have to support all browsers then you could use the css property pointer-events .如果您不必支持所有浏览器,那么您可以使用 css 属性pointer-events 。 When set to none all events will be ignored.当设置为 none 时,所有事件都将被忽略。 Try toggling pointer-events in this fiddle and see what I mean.尝试在这个小提琴中切换指针事件,看看我的意思。
http://jsfiddle.net/zDygA/ http://jsfiddle.net/zDygA/
pointer-events:none;
I hate to link out, but this is a good article if you need to support IE.我讨厌链接出去,但是如果您需要支持 IE,这是一篇很好的文章。
http://www.vinylfox.com/forwarding-mouse-events-through-layers/ http://www.vinylfox.com/forwarding-mouse-events-through-layers/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.