|
Q876 How can I continually scroll through a document, and when the bottom is reached start at the beginning again?
irt.org | Knowledge Base | JavaScript | Scroll | Q876 [ previous next ]
Q876 How can I continually scroll through a document, and when the bottom is reached start at the beginning again?
It can't be done without knowing roughly how long the document is in
pixels:
<html>
<head><script language="JavaScript"><!--
function myHeight() {
if (document.all)
return document.body.offsetHeight;
else if (document.layers)
return document.body.document.height;
else
return 2000; // approx height (adjust as necessary)
}
function myScroll() {
documentYposition += scrollAmount;
window.scroll(0,documentYposition);
if (documentYposition > documentLength)
documentYposition = 0;
setTimeout('myScroll()',scrollInterval);
}
function start() {
documentLength = myHeight();
myScroll();
}
var documentLength;
var scrollAmount = 100; // scroll by 100 pixels each time
var scrollInterval = 1000; // number of milliseconds between scrolls
var documentYposition = 0;
//--></script>
</head>
<body onLoad="start()">
<ilayer id="body">
Place page contents in here
</ilayer>
</body>
</html>
|
|
|
Copyright © 1996-2009 irt.org, All Rights Reserved.