[Javascript] True element coordinates on mouseevent.

David Lovering dlovering at gazos.com
Tue Nov 4 08:16:24 CST 2003


I believe you can get both relative and absolute coordinates, providing that
the relative object is given as a reference (the handle of the object is
provided in the call, and the XOffset, YOffset pair are returned).  Some
browsers (like Safari) use slightly non-standard coordinate de-referencing,
so either you have to write a call which takes into consideration ALL known
browser oddities (ugh!), or else you stick to just the Mozilla/IE6+ stuff
[which admittedly do things differently from one another].

Personally, I LIKE the use of universal absolute coordinates -- all I have
to do is a simple subtraction of the upper left corner coordinates for the
object I'm working with, and voila! I've got relative coordinates referenced
to it.  If you combine this with intelligent use of the mouseover event
handler (which can deliver the absolute coordinates of the upper left corner
of the "this" object), and the whole thing is pretty straight-forward.

-- Dave Lovering

----- Original Message ----- 
From: "Håkan Magnusson" <hakan at backbase.com>
To: "'[JavaScript List]'" <javascript at LaTech.edu>
Sent: Tuesday, November 04, 2003 5:39 AM
Subject: [Javascript] True element coordinates on mouseevent.


> Hi.
>
> Is detecting the true element mouse coordinates (the exact coordinates
> of the mouse pointer on the element it's currently hovering,
> [event.]layerX/layerY (only absolutely position/Mozilla) or
> [event.]offsetX/offsetY(IE/Safari only)) still impossible? I remember
> trying to do this a few years back, when I found out that it only worked
> for elements with position: absolute, and that makes the function
> completely useless and very stupid indeed.
>
> I'm running some tests now, but none of them makes me very happy.
>
> Regards,
> Håkan
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>





More information about the Javascript mailing list