S
steven acer
i'm illiterate when it comes to javascript and browser issues, i'm
trying to code a small help module for my java app.i've went far
enough coding all the server side but i'm stuck with javascript now.
i'm trying to implement a tool tip behavior on a couple of input
element.
I just can't get to figure out the coordinates of the element in
question with respect to the page
especially when it is inside a scrollable container such as a DIV.
the tip has to be displayed right at the bottom left corner of the
element where the key is pressed therefor i would have to calculate
the coordinates of the element's current position on the page
regardless of how nested it is and taking into account the scrolled
amount of its parent container and ancestors each time.
i tried Peter-Paul Koch's findPos and tweeked it a bit as follows
function findPos(obj) {
if(obj==null)return [-1,-1];
var curleft =0;
var curTop=0;
if (obj.offsetParent) {
curleft = obj.offsetLeft;
curtop = obj.offsetTop;
while (obj = obj.offsetParent) {
curtop += obj.offsetTop-(obj.scrollTop?obj.scrollTop:0);
curleft += onj.offsetLeft(obj.scrollLeft?obj.scrollLeft:0);
}
}
return [curleft,curtop];
the problem is that offsetTop is not updated when i scroll.... i
always get a fixed value so that was not helping
thanks
o explanation ...
trying to code a small help module for my java app.i've went far
enough coding all the server side but i'm stuck with javascript now.
i'm trying to implement a tool tip behavior on a couple of input
element.
I just can't get to figure out the coordinates of the element in
question with respect to the page
especially when it is inside a scrollable container such as a DIV.
the tip has to be displayed right at the bottom left corner of the
element where the key is pressed therefor i would have to calculate
the coordinates of the element's current position on the page
regardless of how nested it is and taking into account the scrolled
amount of its parent container and ancestors each time.
i tried Peter-Paul Koch's findPos and tweeked it a bit as follows
function findPos(obj) {
if(obj==null)return [-1,-1];
var curleft =0;
var curTop=0;
if (obj.offsetParent) {
curleft = obj.offsetLeft;
curtop = obj.offsetTop;
while (obj = obj.offsetParent) {
curtop += obj.offsetTop-(obj.scrollTop?obj.scrollTop:0);
curleft += onj.offsetLeft(obj.scrollLeft?obj.scrollLeft:0);
}
}
return [curleft,curtop];
the problem is that offsetTop is not updated when i scroll.... i
always get a fixed value so that was not helping
thanks
o explanation ...