The scrollBy()
method scrolls the content by the specified number of pixels.
scrollBy |
Yes | Yes | Yes | Yes | Yes |
window.scrollBy(xnum, ynum)
Parameter | Description |
---|---|
xnum | Required. pixels to scroll by along the x-axis (horizontal). Positive values scroll to the left, while negative values scroll to the left |
ynum | Required. pixels to scroll by along the y-axis (vertical). Positive values scroll up, while negative values scroll down |
No return value.
The following code shows how to scroll the content by 100px horizontally.
<!DOCTYPE html>
<html>
<body>
<button onclick="scrollWin()" style="position:fixed;">test</button><br><br>
<div style="border:1px solid black;background-color:lightblue;height:75px;width:5000px;">
</div><!-- w ww.j av a 2 s . c o m-->
<script>
function scrollWin()
{
window.scrollBy(100,0);
}
</script>
</body>
</html>
The code above is rendered as follows: