The JavaScript Window scrollTo() method is used to scroll the current document to a specific position. It takes two arguments: the horizontal position to scroll to, and the vertical position to scroll to. It does not return a value.
Here are some examples of how the scrollTo() method can be used in JavaScript code:
- To scroll the current document to a specific position, you can use the following code:
window.scrollTo(100, 50);
- To scroll the current document to the top of the page, you can use the following code:
window.scrollTo(0, 0);
- To scroll the current document to the bottom of the page, you can use the following code:
var height = document.body.scrollHeight;
window.scrollTo(0, height);
Overall, the scrollTo() method provides a convenient way to scroll the current document to a specific position. It can be used for tasks such as scrolling to the top or bottom of the page, or other operations that require setting the scroll position of the document.
Leave a Reply