faqts : Computers : Programming : Languages : JavaScript : DHTML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

46 of 54 people (85%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How can I implement scrollIntoView for NN6?

Feb 15th, 2009 21:51
Inschi jelii, Martin Honnen,


Here is the code. I only tested for the img element and the layer but I 
believe it is going to work for other elements as well (as long as NN6 
is delivering the correct offsetLeft/offsetTop values).
<html>
<head>
<script language="JavaScript1.5">
function HTMLElement_getPageCoords () {
  var coords = {x: 0, y: 0};
  var el = this;
  do {
    coords.x += el.offsetLeft;
    coords.y += el.offsetTop;
  }
  while ((el = el.offsetParent));
  return coords;
}
HTMLElement.prototype.getPageCoords = HTMLElement_getPageCoords;
function HTMLElement_scrollIntoView () {
  var coords = this.getPageCoords();
  window.scrollTo (coords.x, coords.y);
}
HTMLElement.prototype.scrollIntoView = HTMLElement_scrollIntoView;
</script>
</head>
<body>
<input type="button"
       value="scroll image into view"
       onclick="document.imageName.scrollIntoView();"
/>
<input type="button"
       value="scroll layer into view"
       onclick="document.getElementById('aLayer').scrollIntoView();"
/>
<div id="aLayer"
     style="position: absolute;
            left: 1500px;
            top: 400px;
            background-color: yellow;"
>
Kibology for all
</div>
<script>
for (var i = 0; i < 30; i++)
  document.write(i + ' Kibology<br \/>');
</script>
All for Kibology
<img name="imageName" src="kiboInside.gif" />
</body>
</html>
http://lahjatideoita.blogspot.com
http://ideaspara-regalar.blogspot.com
http://idearegalo1.blogspot.com
http://geschenkeidee.blogspot.com
http://darkovenapady.blogspot.com