简体   繁体   中英

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:

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?

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

pointer-events:none;

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM