Posts

Showing posts from July, 2008

Finding Postions of HTML Element in a Scrollable Div

Hi Friends, Have you ever find it difficult to find the x, y coordinates value for a HTML element in side a scrollable div. Just few days back, i got this problem. where i wanted to show tool tip on a link, but since the HTML element was in a scrollable div, the positioning to tooltip was not correct. Here is the code earlier i used to find the X and Y positions: function findPosX(obj) { var curleft = 0; if (obj.offsetParent) { while (obj.offsetParent) { curleft += obj.offsetLeft obj = obj.offsetParent; } } else if (obj.x) curleft += obj.x; return curleft; } function findPosY(obj) { var curtop = 0; if (obj.offsetParent) { while (obj.offsetParent) { curtop += obj.offsetTop obj = obj.offsetParent; } } else if (obj.y) curtop += obj.y; return curtop; } This function works well when your HTML element is not within a scrollable div. B