Saturday, 15 March 2014

How to Auto-scroll Pages in Javascript

Problem
You want the entire browser page to automatically scroll vertically for the user.
Solution
All current mainstream scriptable browsers empower their window objects with a scrollBy( ) method. By invoking it repeatedly through a setInterval( ) call, you can scroll the browser window with no user interaction. The following function and setInterval( ) call do the trick:
function scrollWindow( ) {
window.scrollBy(0, 1);
}
function initScroll( ) {
setInterval("scrollWindow( )", 100);
}
The initScroll( ) function should be invoked by a load event of the window object.

No comments:

Post a Comment