1

Is there a way to detect mouse events (hover, click, ...) on elements that are behind other HTML elements but not within the same DOM path (i.e. events do not bubble up to the element)?

A quick example to clarify what I mean: http://jsfiddle.net/xeJyg/1/

At the moment I don't see other option except for registering the event handler on the first common parent (in the example above that would be <BODY>) and check myself if the event happened above the element in question. The problem is that with many elements this will probably become very inefficient.

In the long turn I try to catch mouse events for markers on multiple OpenLayer layers, which is not supported out of the box (events work only for the top layer).

Udo G
  • 12,572
  • 13
  • 56
  • 89
  • 1
    I think that http://stackoverflow.com/questions/1737480/passing-mouse-clicks-through-an-overlaying-element-div may give you a start. – verisimilitude Jun 05 '12 at 13:02
  • Thanks, but that comes close to my mentioned inefficient do-it-yourself method and I dont really like to hide/show a number of layers containing a few hundred markers on mousemove... :-/ – Udo G Jun 05 '12 at 13:16

1 Answers1

3

on newer browser you can use pointer-events: none;

#cover {
    ...
    pointer-events: none;
}

fiddle: http://jsfiddle.net/PVxbq/

Fabrizio Calderan
  • 120,726
  • 26
  • 164
  • 177
  • 1
    That would still only allow me to receive events on a single layer. However, I have several layers with markers and I need to catch events for all layers/events. – Udo G Jun 05 '12 at 13:14
  • Actually that was indeed an important hint. It turned out that only the OpenLayers *Vector* layers blocked mouse events and setting `pointer-events:none` for those layers solves the problem (since I only need mouse events on Markers, not Vectors). +1 for solving my main problem. I let the original question open since it is still not solved. – Udo G Jun 05 '12 at 14:01
  • Shoulda guessed it wouldn't work on IE9 when you said "newer browser"; Boo for IE :( – Christopher Lightfoot Dec 10 '12 at 11:05
  • @widgisoft , probably "modern" would have been a better adjective: http://caniuse.com/pointer-events – Fabrizio Calderan Dec 10 '12 at 12:49