I want to get the top and left values for a div on the screen.
I have been using the code to calculate the top and left values.
var total1 = 0;
var total2 = 0;
while(element){
total1+=element.offsetTop;
total2+=element.offsetLeft;
try{
element=element.offsetParent;
}catch(E){
break;
}
}
For the same DOM TREE this code is giving a performance reading of 30msec in IE8 and 80 to 200msec in IE6. I want to gain a considerable performance improvement in IE6.
I am open to all ideas.
By the way I also tried
var total1 = 0;
var total2 = 0;
do{
total1+=element.offsetTop;
total2+=element.offsetLeft;
}while(element=element.offsetParent);
after reading a blog entry or two. The performace is similar.
I found that the bulk of the time is always spent in getting property value rather than parsing the DOM TREE which less constantly from my logs.(I might be wrong)
Also the code I have put here is on the fly....might have made mistakes.
Am looking at performance gain. The floor is open to try anything only constraint is just javascript, jquery, prototype etc are not an option.
Thanks in advance!! :)