Javascript examples for Browser Object Model:Window scrollBy
The scrollBy() method scrolls the document by the specified number of pixels.
Parameter | Type | Description |
---|---|---|
xnum | Number | Required. pixels to scroll along the x-axis. Both positive / negative are allowed |
ynum | Number | Required. pixels to scroll along the y-axis. Both positive / negative are allowed |
No return value
The following code shows how to Scroll the document by 100px horizontally:
<!DOCTYPE html> <html> <head> <style> body {/* ww w . ja va2 s . c o m*/ height: 7500px; width: 5000px; } button { position: fixed; } </style> </head> <body> <button onclick="scrollWin(0, 50)">Scroll down</button><br><br> <button onclick="scrollWin(0, -50)">Scroll up</button><br><br> <button onclick="scrollWin(100, 0)">Scroll right</button><br><br> <button onclick="scrollWin(-100, 0)">Scroll left</button><br><br> <script> function scrollWin(x, y) { window.scrollBy(x, y); } </script> </body> </html>