Last Comment Bug 122665 - Event.layerX should be Event.offsetX
: Event.layerX should be Event.offsetX
Product: Core
Classification: Components
Component: DOM: Events (show other bugs)
: Trunk
: All All
-- enhancement (vote)
: ---
Assigned To: joki (gone)
: Vladimir Ermakov
: Andrew Overholt [:overholt]
Depends on:
  Show dependency treegraph
Reported: 2002-01-30 13:04 PST by Giscard Girard
Modified: 2002-07-08 11:59 PDT (History)
2 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Description User image Giscard Girard 2002-01-30 13:04:05 PST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:0.9.7) Gecko/20011221
BuildID:    Gecko/20011221

For compatibility with Internet Explorer.  The event property layerX should be
wrapped as Event.offsetX
Comment 1 User image Boris Zbarsky [:bz] (still a bit busy) 2002-01-30 23:31:04 PST
Comment 2 User image Vladimir Ermakov 2002-02-06 14:13:32 PST
really confirming
Comment 3 User image Gérard Talbot 2002-07-04 17:39:53 PDT
I strongly disagree with any project to rename evt.layerX/Y properties as MSIE
5+'s event.offsetX/Y. These event properties are absolutely not the same.

In 1 sentence, their major difference is about whether the target element is
(absolutely or relatively) positioned or not, or if the target element is within
a (absolutely or relatively) positioned containing element.

MSIE event.offsetX/Y properties will store the X/Y mouse coordinate within the
target element (i.e. clicking inside an <img>), and this, regardless of
positioning context. 

There is no built-in equivalent to MSIE's event.offsetX/Y in NS 6+. NS 6+
evt.layerX/Y properties are NOT the MSIE 5.x and 6 equivalent of event.offsetX/Y
properties. Under NS 6+, it is possible to calculate the offsetX/Y values.

Here's a way to get the equivalent of MSIE 5+ event.offsetX/Y properties:

var Element = ;
var CalculatedTotalOffsetLeft = CalculatedTotalOffsetTop = 0 ;
while (Element.offsetParent)
	CalculatedTotalOffsetLeft += Element.offsetLeft ;
	CalculatedTotalOffsetTop += Element.offsetTop ;
	Element = Element.offsetParent ;

OffsetXForNS6 = evt.pageX - CalculatedTotalOffsetLeft ;
OffsetYForNS6 = evt.pageY - CalculatedTotalOffsetTop ;

NS 6+ evt.layerX/Y properties calculate the distance from the left/top corner of
an element if it is absolutely or relatively positioned; if it's not positioned,
then the values are the distance from the left/top of its closest absolutely or
relatively positioned containing element. In case the target element has no
positioned element within the containment hierarchy, then the body element is
the positioned containing element[1].

Here's an interactive demo on evt.layerX/Y :

[1]: there are 2 exceptions to this: input type="text" and textarea elements.
When an event is fired, the evt.layerX/Y will return the X/Y mouse coordinate
within the input type="text" or within the textarea regardless of positioning
context. These 2 exceptions AFAIK are undocumented.
Comment 4 User image Boris Zbarsky [:bz] (still a bit busy) 2002-07-04 21:24:28 PDT
Wontfix then, since the two are different things.  Thanks for the info!
Comment 5 User image Vladimir Ermakov 2002-07-08 11:59:24 PDT

Note You need to log in before you can comment on or make changes to this bug.