views:

129

answers:

1

If I use for example a mousemove event handler on a div and check the layerX property of the event, it changes when my mouse enters a positioned element inside that div (like an image).

According to the jQuery Event object documentation it should follow the W3C DOM Level 3 specifications. But there's no mention of the layerX/Y property for the MouseEvent interface, so I'm wondering what behavior is according to specification?

To me it seems that you always want the layerX/Y to be relative to the layer that fires the event, if I wanted the layerX/Y of a nested element, I would check the event in a different phase (bubbling) or would attach my handler to that nested element.

My question is (somewhat subjective): how should layerX/Y work?

+1  A: 

I would think that layerx/y would be the offset from the first parent node of the firing element that has position (relative or absolute). Either way, jQuery has better ways of finding positions like this and also LayerX/Y cannot be guaranteed to be the same in every browser, so I wouldn't use it

Bob Fincheimer
Thanks, I changed the code to use a combination of element.offset().left and e.clientX
michielvoo