problems with positions -
07-22-2003
, 11:01 AM
Hi
Im making an advanced tooltip for my page, but ive run into a problem.
The yellow box is made of a span tag thats positioned absolutely and
moved around to the different objects that needs to show a tooltip. But
when the object is too close to the buttom of the screen the tooltip is
positioned outside the layout of the page, and completly ruins my
design. so basicaly I want to calculate if the div tag is (partly)
positioned outside the document area, before I make it visible. My code
is very simple:
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;
}
function showHint(showThis, underThis) {
elem = document.getElementById(showThis);
elem2 = document.getElementById(underThis);
elem.style.left = findPosX(elem2);
elem.style.top = findPosY(elem2)+15;
elem.style.visibility='visible';
}
function hideHint(hideThis) {
elem = document.getElementById(hideThis);
elem.style.visibility='hidden';
}
and what I want to do is to calc new style.left and style.top for elem
if its outside the document. I just dont have a clue as to how its done!
can someone give me a few hints?
- Kasper |