K
Keith Thornhill
I'm trying to calculate the top and left distance from the side of the
browser of an object (either absolutely or relatively positioned) and i'm
running into a weird problem as i'm trying to make the code cross-browser.
normally i simply use the .offsetLeft/Top properties of the object to get my
numbers, and it is as simple as that. but in Firefox (v. 0.9.3), they both
return the value "8" no matter where the object appears on the page.
i've tried many ways to make this work, and always with the same results.
my current proof of concept page (included below) contains two methods (one
direct and one recursive) which both work in IE (v. 6) and Opera (v. 7.54)
any help to get this working in Firefox would be greatly appreciated.
thanks,
keith
----------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<table align="center" id="table" border="1">
<tr>
<td>test</td>
</tr>
</table>
<br>
<br>
table is
<script>
var left;
left = document.getElementById("table").offsetLeft;
document.write(left);
document.write(" and ");
var Element = document.getElementById("table");
var CalculatedTotalOffsetLeft;
CalculatedTotalOffsetLeft = 0;
while (Element.offsetParent) {
CalculatedTotalOffsetLeft += Element.offsetLeft ;
Element = Element.offsetParent ;
}
document.write(CalculatedTotalOffsetLeft);
</script>
px away from left of screen.<br>
<br>
</body>
</html>
----------------------------------------------------
browser of an object (either absolutely or relatively positioned) and i'm
running into a weird problem as i'm trying to make the code cross-browser.
normally i simply use the .offsetLeft/Top properties of the object to get my
numbers, and it is as simple as that. but in Firefox (v. 0.9.3), they both
return the value "8" no matter where the object appears on the page.
i've tried many ways to make this work, and always with the same results.
my current proof of concept page (included below) contains two methods (one
direct and one recursive) which both work in IE (v. 6) and Opera (v. 7.54)
any help to get this working in Firefox would be greatly appreciated.
thanks,
keith
----------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<table align="center" id="table" border="1">
<tr>
<td>test</td>
</tr>
</table>
<br>
<br>
table is
<script>
var left;
left = document.getElementById("table").offsetLeft;
document.write(left);
document.write(" and ");
var Element = document.getElementById("table");
var CalculatedTotalOffsetLeft;
CalculatedTotalOffsetLeft = 0;
while (Element.offsetParent) {
CalculatedTotalOffsetLeft += Element.offsetLeft ;
Element = Element.offsetParent ;
}
document.write(CalculatedTotalOffsetLeft);
</script>
px away from left of screen.<br>
<br>
</body>
</html>
----------------------------------------------------