Javascript examples for Browser Object Model:Window scrollTo
The scrollTo() method scrolls the document to the specified coordinates.
Parameter | Type | Description |
---|---|---|
xpos | Number | Required. The coordinate to scroll to, along the x-axis (horizontal), in pixels |
ypos | Number | Required. The coordinate to scroll to, along the y-axis (vertical), in pixels |
No return value
The following code shows how to Scroll the document to the horizontal position "500":
<!DOCTYPE html> <html> <head> <style> body {/* ww w. j av a2 s. c om*/ width: 5000px; } </style> </head> <body> <button onclick="scrollWin()">Click me to scroll</button> <br> <br> <p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p> <br> <br> <br> <br> <br> <br> <br> <br> <p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p> <br> <br> <br> <br> <br> <br> <br> <p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p> <br> <br> <br> <br> <br> <br> <br> <br> <p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p> <br> <br> <br> <br> <br> <br> <br> <br> <p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p> <br> <br> <br> <br> <br> <br> <br> <br> <p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p> <br> <br> <br> <br> <br> <br> <br> <br> <p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p> <br> <br> <br> <br> <br> <br> <br> <br> <p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p> <br> <br> <br> <br> <br> <br> <br> <br> <p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p> <br> <br> <br> <br> <br> <br> <br> <br> <script> function scrollWin() { window.scrollTo(300, 500); } </script> </body> </html>