SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
-
Jul 8, 2004, 06:30 #1
- Join Date
- Mar 2004
- Location
- united states
- Posts
- 178
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
bug in calculating the position of an element
Hello
I wrote a function which will find the exact top left coordinates in the screen.
The function will return an associative array with information on the element:
Code:function getPositionAndDimension(element) { var left = 0; var top = 0; var width = element.offsetWidth; var height = element.offsetHeight; while (element.parentElement != null) { left += element.offsetLeft; top += element.offsetTop; element = element.parentElement; } var results = new Array(4); results['left'] = left; results['top'] = top; results['width'] = width; results['height'] = height; return results; }
I am getting values that are much larger than the actual top value.
can anyone see where the bug is in?
I am testing this on IE6
thanks
-
Jul 8, 2004, 08:10 #2
- Join Date
- Apr 2004
- Location
- Lviv, Ukraine
- Posts
- 129
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Take a look at klayers library - a nice bundle of useful cross-browser DHTML functions.
Bookmarks