The scrollTo()
method scrolls the content to the specified coordinates.
scrollTo |
Yes | Yes | Yes | Yes | Yes |
window.scrollTo(xpos, ypos)
Parameter | Description |
---|---|
xpos | Required. The coordinate to scroll to, along the x-axis (horizontal) |
ypos | Required. The coordinate to scroll to, along the y-axis (vertical) |
No return value.
The following code shows how to scroll the content to the horizontal position 500.
<!DOCTYPE html>
<html>
<body>
<button onclick="scrollWin()">test</button><br><br>
<div style="border:1px solid black;background-color:lightblue;height:75px;width:5000px;">
</div><!--from w w w . j a v a 2 s. co m-->
<script>
function scrollWin()
{
window.scrollTo(500,0);
}
</script>
</body>
</html>
The code above is rendered as follows: