tygre
11-19-2002, 06:56 PM
Hello,
I am a newbie with Mozilla. I am trying to get the scrollLeft position of a div that is contained in another div. I know that scrollLeft (IE only) is not implemented in Mozilla, but according to the W3C docs offsetLeft should do the job. The way I read it, I should get the offset compared to the parent element. All I ever get is the offset left of the containing div. I am including some sample code. Could somone help me out?
If you try the code, size the browser so that a scrollbar appears on the div, scroll using the arrow button, then click the button for a list of all the values I have attempted to test for.
Thanks in advance!
<html>
<head>
<script>
function report()
{
var div = document.getElementById("Test");
var dfp = div.firstChild.parentNode;
var dfn = dfp.firstChild.nextSibling;
var dfn2 = dfn.firstChild.nextSibling;
var sMsg = "div: document.getElementById(\"Test\")\n" +
"dfp: div.firstChild.parentNode\n" +
"dfn: dfp.firstChild.nextSibling\n" +
"dfn2: dfn.firstChild.nextSibling\n" +
"div.className: " + div.className + "\n" +
"div.firstChild.nodeName: " + div.firstChild.nodeName + "\n" +
"div.firstChild.nodeType: " + div.firstChild.nodeType + "\n" +
"dfp.nodeName: " + dfp.nodeName + "\n" +
"dfp.nodeType: " + dfp.nodeType + "\n" +
"dfp.className: " + dfp.className + "\n" +
"dfp.firstChild.nodeName: " + dfp.firstChild.nodeName + "\n" +
"dfp.firstChild.nodeType: " + dfp.firstChild.nodeType + "\n" +
"dfn.nodeName: " + dfn.nodeName + "\n" +
"dfn.nodeType: " + dfn.nodeType + "\n" +
"dfn.className: " + dfn.className + "\n" +
"dfn.id: " + dfn.id + "\n" +
"dfn.offsetLeft: " + dfn.offsetLeft + "\n" +
"dfn.pageX: " + dfn.pageX + "\n" +
"dfn.clientX: " + dfn.clientX + "\n" +
"dfn.style.left: " + dfn.style.left + "\n" +
"dfn.getAttribute(\"left\"): " + dfn.getAttribute("left") + "\n" +
"dfn.getAttribute(\"offsetLeft\"): " + dfn.getAttribute("offsetLeft") + "\n" +
"dfn2.nodeName: " + dfn2.nodeName + "\n" +
"dfn2.nodeType: " + dfn2.nodeType + "\n" +
"dfn2.className: " + dfn2.className + "\n" +
"dfn2.style: " + dfn2.style + "\n" +
"dfn2.style.borderLeft: " + dfn2.style.borderLeft + "\n" +
"dfn2.style.left: " + dfn2.style.left + "\n" +
"dfn2.offsetLeft: " + dfn2.offsetLeft + "\n" +
"window.scrollX : " + window.scrollX + "\n" +
"window.pageXOffset : " + window.pageXOffset + "\n";
alert (sMsg);
}
</script>
</head>
<body>
<button onclick="report();">Report Values</button><br>
<div class='ScrollBodyBoth' id="Test" style="height: 275px; width: 100%; padding-left: 15px; overflow: auto;">
<div style='width:600px;' id="testID" class="testClass">
<table class='ScrollBodyContent' cellspacing='0' cellpadding='2'>
<colgroup>
<col width='150px' align='left'>
<col width='150px' align='center'>
<col width='150px' align='center'>
<col width='150px' align='center'>
</colgroup>
<tbody>
<tr class="ScrollBodyContent">
<td>blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah</td>
<td>blahblah</td>
<td>blahblah</td>
<td>blahblahblah</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
I am a newbie with Mozilla. I am trying to get the scrollLeft position of a div that is contained in another div. I know that scrollLeft (IE only) is not implemented in Mozilla, but according to the W3C docs offsetLeft should do the job. The way I read it, I should get the offset compared to the parent element. All I ever get is the offset left of the containing div. I am including some sample code. Could somone help me out?
If you try the code, size the browser so that a scrollbar appears on the div, scroll using the arrow button, then click the button for a list of all the values I have attempted to test for.
Thanks in advance!
<html>
<head>
<script>
function report()
{
var div = document.getElementById("Test");
var dfp = div.firstChild.parentNode;
var dfn = dfp.firstChild.nextSibling;
var dfn2 = dfn.firstChild.nextSibling;
var sMsg = "div: document.getElementById(\"Test\")\n" +
"dfp: div.firstChild.parentNode\n" +
"dfn: dfp.firstChild.nextSibling\n" +
"dfn2: dfn.firstChild.nextSibling\n" +
"div.className: " + div.className + "\n" +
"div.firstChild.nodeName: " + div.firstChild.nodeName + "\n" +
"div.firstChild.nodeType: " + div.firstChild.nodeType + "\n" +
"dfp.nodeName: " + dfp.nodeName + "\n" +
"dfp.nodeType: " + dfp.nodeType + "\n" +
"dfp.className: " + dfp.className + "\n" +
"dfp.firstChild.nodeName: " + dfp.firstChild.nodeName + "\n" +
"dfp.firstChild.nodeType: " + dfp.firstChild.nodeType + "\n" +
"dfn.nodeName: " + dfn.nodeName + "\n" +
"dfn.nodeType: " + dfn.nodeType + "\n" +
"dfn.className: " + dfn.className + "\n" +
"dfn.id: " + dfn.id + "\n" +
"dfn.offsetLeft: " + dfn.offsetLeft + "\n" +
"dfn.pageX: " + dfn.pageX + "\n" +
"dfn.clientX: " + dfn.clientX + "\n" +
"dfn.style.left: " + dfn.style.left + "\n" +
"dfn.getAttribute(\"left\"): " + dfn.getAttribute("left") + "\n" +
"dfn.getAttribute(\"offsetLeft\"): " + dfn.getAttribute("offsetLeft") + "\n" +
"dfn2.nodeName: " + dfn2.nodeName + "\n" +
"dfn2.nodeType: " + dfn2.nodeType + "\n" +
"dfn2.className: " + dfn2.className + "\n" +
"dfn2.style: " + dfn2.style + "\n" +
"dfn2.style.borderLeft: " + dfn2.style.borderLeft + "\n" +
"dfn2.style.left: " + dfn2.style.left + "\n" +
"dfn2.offsetLeft: " + dfn2.offsetLeft + "\n" +
"window.scrollX : " + window.scrollX + "\n" +
"window.pageXOffset : " + window.pageXOffset + "\n";
alert (sMsg);
}
</script>
</head>
<body>
<button onclick="report();">Report Values</button><br>
<div class='ScrollBodyBoth' id="Test" style="height: 275px; width: 100%; padding-left: 15px; overflow: auto;">
<div style='width:600px;' id="testID" class="testClass">
<table class='ScrollBodyContent' cellspacing='0' cellpadding='2'>
<colgroup>
<col width='150px' align='left'>
<col width='150px' align='center'>
<col width='150px' align='center'>
<col width='150px' align='center'>
</colgroup>
<tbody>
<tr class="ScrollBodyContent">
<td>blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah</td>
<td>blahblah</td>
<td>blahblah</td>
<td>blahblahblah</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>