JavaScript Window scrollTo() method

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:

  1. To scroll the current document to a specific position, you can use the following code:
window.scrollTo(100, 50);
  1. To scroll the current document to the top of the page, you can use the following code:
window.scrollTo(0, 0);
  1. 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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: