views:

26

answers:

2

Is there a way in JavaScript to propagate events to elements obscured by another one? Because I have an element with position: absolute that obscures elements that aren't parent elements of it, but I'd like click, mousemove and mousout events to pass through this element. The solution can be Mozilla Firefox specific, because I'll use it in a Firefox Add-On.

A: 

You could use getElementsByTagName("*") to get all elements in the page. Using a find-world-position function, you could get the position of an element relative to the top left corner of the page. You could now use offsetWidth, offsetHeight, and mouse position [browser specific, lol] to check if the cursor is over your element.

If the cursor is over your element, fire the event.

The above function should be attached to window.onmousedown/onmouseup/onmousemove/whatever

ItzWarty
Yeah, I hoped there would be something easier and faster. Maybe putting an invisible `<img>` with an associated image map in front of the `<canvas>` (that's the obscuring element) would be better. Hmmm.
panzi
+1  A: 

Maybe the css property pointer-events:none; is what you looking for. It's used on the twitter homepage for example, so you can click on the text in the "trending topics" also when it overlay by fade out graphics.

eskimoblood
Thank you. That is what I was looking for.
panzi