[Javascript] getting position

Chris T christ at saeweb.com
Tue Jun 22 10:04:52 CDT 2004


Does this take into consideration if it's nested within other elements?


----- Original Message ----- 
From: "Laurent Muchacho" <LaurentM at london.virgin.net>
To: "'[JavaScript List]'" <javascript at LaTech.edu>
Sent: Tuesday, June 22, 2004 10:50 AM
Subject: RE: [Javascript] getting position


> Hi,
>
> I think this is what you look for this function will return the absolute
> position of an element when you call the function getAbsX(elt) or
> getAbsY(elt) elt must be
> equal to document.all['yourid'] or document.getElementById('yourid') or
> document.layers['yourid']
> <div id="yourid">whatever</div>
>
> if you want to use this function in ns4 you must put a name as well
> <div id="yourid" name="yourid">whatever</div>
>
>
> function getAbsX(elt) { return parseInt(elt.x) ? elt.x :
> getAbsPos(elt,"Left"); };
> function getAbsY(elt) { return parseInt(elt.y) ? elt.y :
> getAbsPos(elt,"Top"); };
> function getAbsPos(elt,which) {
>  iPos = 0;
>  while (elt != null) {
>   iPos += elt["offset" + which];
>   elt = elt.offsetParent;
>  }
>  return iPos;
> };
>
> ps : I'm not the author of this function I found the logic on the net a
> while ago I just implemented it to my need.
> ps : this function work really well when
> 1. you use an image with a name and an id
> 2. If you use IE MAC don't write dynamcly your html in the page with
> javascript like document.write('<div id="yourid"
> name="yourid">whatever</div>') the IE browser on the mac will get confuse
> and give you really wrong value from what to expect.
>
>
> -----Original Message-----
> From: Iztok Polanic [mailto:iztokp at amis.net]
> Sent: 22 June 2004 15:35
> To: javascript at LaTech.edu
> Subject: [Javascript] getting position
>
>
> Hi!
>
> I'm wondering how to get a position (x, Y) of an object by its ID. How to
do
> this?
>
>
> Bye,
>
> Iztok
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>
> This E-mail and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they are
addressed.  If you have received this E-mail in error please notify the
system manager.  This message contains confidential information and is
intended only for the individual named.  If you are not the named addressee
you should not disseminate, distribute or copy this E-mail.
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list