Thursday, July 22, 2010

Javascript scroll to bottom of page

2 comments
This code snippet provides a javascript function to scroll a HTML page
programatically to the bottom on page load. Make the browser height
smaller to observe the scrolling effect.

The javascript.

window.onload=toBottom;

function toBottom()
{
alert("Scrolling to bottom ...");
window.scrollTo(0, document.body.scrollHeight);
}


The test html code.
<html>
<head>
<script src="testme.js" language="javascript" type="text/javascript"></script>
</head>
<body>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
Some big text<br>
</body>
</html>
If You Enjoyed This, Take 5 Seconds To Share It

2 comments:

  1. very cool & good js tip, thank you very much for sharing.

    ReplyDelete
  2. How do you control the speed that this thing scrolls so you can make it smooth, yet not take forever if the page is really long? And can you think of a way to make the scrolling speed increase as the page scrolls?

    ReplyDelete