[Javascript] getting position

Troy III Ajnej trojani2000 at hotmail.com
Tue Jun 22 11:40:31 CDT 2004


Hi there, does the a, getAbsX &/or Y apply for traditionally casscading 
elements, that is, -not absolutely nor relatively positioned elements in the 
page?

>From: Laurent Muchacho <LaurentM at london.virgin.net>
>Reply-To: "[JavaScript List]" <javascript at LaTech.edu>
>To: "'[JavaScript List]'" <javascript at LaTech.edu>
>Subject: RE: [Javascript] getting position
>Date: Tue, 22 Jun 2004 15:50:37 +0100
>
>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

_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE* 
http://join.msn.com/?page=features/junkmail




More information about the Javascript mailing list