JavaScript Page Scroll Tutorial and Example

Today I wrote a simple JavaScript that scrolls down the page slowly for a certain amount of time, and then goes back up to the top of the page and starts scrolling again.

Get Chitika eMiniMalls


<html>
<head>
<script type="text/javascript">
scrolldelay = "";
function pageScroll() {
window.scrollBy(0,1); //Scroll 1px. Makes it smoother
scrolldelay = setTimeout('pageScroll()',50); //Scroll every 50ms
}
function startScroll() {
window.scroll(0,0);
clearTimeout(scrolldelay);
pageScroll();
scrolldelay = setTimeout('startScroll()',20000); //Repeat every 20 seconds
}
</script>
</head>
<body onLoad="startScroll()">
Put body text here
</body>
</html>

I used this code for a client who wanted a web page to be displayed publicly without needing to have a user do the work.

Let me know if you found this helpful!

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>