Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: SV: How to find the absolute position of an object


Message #1 by "Robert Nyman" <robert.nyman@c...> on Mon, 9 Dec 2002 12:45:18 +0100
offsetLeft and offsetTop do not give ABSOLUTE position on a page - they
give position relative to the containing object.

If the image you want is inside another element, you have to work your way 
up the tree by using the offsetParent property and adjusting the position 
until you run out of parents.

-Van

> Hi Trent,

In IE 4+, Netscape 6+, and Opera (however, instable in version 6 but ok
in version 7),
you can use the offsetLeft and offsetTop property for the image, as in:

<img src=3D"yourImage.jpg" alt=3D"" width=3D"160" height=3D"120" =
border=3D"0"
onClick=3D"alert('Left: ' + this.offsetLeft + '\nTop: ' +
this.offsetTop);">


/Robert


-----Ursprungligt meddelande-----
Fr=E5n: Trent Blackburn [mailto:puzzlepants@m...]=20
Skickat: den 8 december 2002 23:48
Till: JavaScript HowTo
=C4mne: [javascript_howto] How to find the absolute position of an =
object


Hello All

Is there a way to find the absolute position of an object when the page=20
loads?

What I have is an image on the page, and I want to place a table in a
div=20
over that image in an attempt to create a grid, but I run into problems=20
when the user's screen resolution changes. So, I would like to find the=20
absolute position of the image and input those cordinates into the div.

Thanks in advance.
---
Change your mail options at http://p2p.wrox.com/manager.asp or=20
to unsubscribe send a blank email to


  Return to Index