auto scroll down in javascript code example

Example 1: php auto scoll page with output

<script>
var scroller = setInterval(function() {  
    window.scrollTo(0,document.body.scrollHeight);
}, 10); // update every 10 ms, change at will
</script>
<?php
// generate 1000 lines of html code
for($i=0; $i<1000; $i++){
    echo $i . "<br>";
    ob_flush(); // flush out the output as we go
    flush(); // same
    usleep(10000); // add some delay to see it in action  
}

?>

<script>
clearInterval(scroller); // stop updating so that you can scroll up 
</script>

Example 2: javascript auto scroll down slowly

function pageScroll() {
    window.scrollBy(0,1);
    scrolldelay = setTimeout(pageScroll,10);
}

Example 3: javascript scroll down

window.scrollTo(300, 500);	//X=300 and Y=500

Tags:

Css Example