I know this is an commonly asked question, but most answers are close but not 100% correct.
The correct way to calculate absolute position of an dom element in IE is:
1 function getCoord(obj, offsetLeft, offsetTop){
2 var orig = obj;
3 var left = 0;
4 var top = 0;
5 if(offsetLeft) left = offsetLeft;
6 if(offsetTop) top = offsetTop;
7 if(obj.offsetParent){
8 left += obj.offsetLeft;
9 top += obj.offsetTop;
10 while (obj = obj.offsetParent) {
11 left += (obj.offsetLeft-obj.scrollLeft+obj.clientLeft);
12 top += (obj.offsetTop-obj.scrollTop+obj.clientTop);
13 }
14 }
15 return {left:left, top:top, width: orig.offsetWidth, height: orig.offsetHeight};
16 }
You will have to use scrollLeft and scrollTop to compensate DIV's scrolling. clientLeft and clientTop are needed to compensate any border width. But that's IE, in firefox clientLeft and clientTop are not available yet, I am having a hard time to adjust scrolling because DIV is never an offsetParent. I guess nothing is perfect.., if my pop up is a few pixels off, so be it =)
- Rushui