How to scroll a window in Javascript

Description

window.scrollTo(x, y) scrolls to the specified position.

Example


<!DOCTYPE HTML> 
<html> 
    <body> 
        <p> 
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
            This is a test. <br/>
<!--   w w  w .j av  a  2 s .  c  om-->
        </p> 
        <script> 
            window.scrollTo(0, 400); 
        </script> 
    </body> 
</html>

Click to view the demo





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window