I am trying to write a script that displays a div of information in a position relative to an element on my page. For example, when you hover over a link I want a div to appear next to the link. Therefore I need to find the position of the link on the page so I can move the div element to the right position.
I have tried a few scripts but none of them work for both IE and Firefox. The top value is always ok but the left value leaves my div in different places depending on browser and size of the browser window. Here is an example script that I have been using.
This supposedly gives me the left and top of my link element but when I try and display my div element at these coordinates it displays in a different place depending on browser type and window size. I want my div element to show in the same place regardless of these factors.
If anyone could give me a script that works or inform me how I could make the above script work that would be great.
I have tried a few scripts but none of them work for both IE and Firefox. The top value is always ok but the left value leaves my div in different places depending on browser and size of the browser window. Here is an example script that I have been using.
Code:
function getPos(obj) {
var pos = {x: obj.offsetLeft||0, y: obj.offsetTop||0};
while(obj = obj.offsetParent) {
pos.x += obj.offsetLeft||0;
pos.y += obj.offsetTop||0;
}
return pos;
}
This supposedly gives me the left and top of my link element but when I try and display my div element at these coordinates it displays in a different place depending on browser type and window size. I want my div element to show in the same place regardless of these factors.
If anyone could give me a script that works or inform me how I could make the above script work that would be great.