...

View Full Version : bug in calculating the position of an element



davidklonski
07-08-2004, 02:29 PM
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:


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;
}

The problem is that the value that the function calculates for the element's top is incorrect.
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

Catman
07-08-2004, 06:00 PM
Have you tried offsetParent instead of parentElement?

davidklonski
07-08-2004, 08:56 PM
yes, that did the trick.
thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum