Event.layerX should be Event.offsetX

VERIFIED WONTFIX

Status

()

Core
DOM: Events
--
enhancement
VERIFIED WONTFIX
16 years ago
15 years ago

People

(Reporter: Giscard Girard, Assigned: joki (gone))

Tracking

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

16 years ago
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
confirming.
Hardware: PC → All

Comment 2

16 years ago
really confirming
Status: UNCONFIRMED → NEW
Ever confirmed: true

Comment 3

15 years ago
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 = evt.target ;
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 :

http://www.geocities.com/Area51/Realm/8655/HTMLJavascriptCSS/PositioningEvtLayer.html

----
[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.
Wontfix then, since the two are different things.  Thanks for the info!
Status: NEW → RESOLVED
Last Resolved: 15 years ago
Resolution: --- → WONTFIX

Comment 5

15 years ago
verifying
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.