How to get and set the current web page scroll position with JavaScript?

Spread the love

Sometimes, we want to get and set the current web page scroll position with JavaScript.

In this article, we’ll look at how to get and set the current web page scroll position with JavaScript.

How to get and set the current web page scroll position with JavaScript?

To get and set the current web page scroll position with JavaScript, we set the scrollTop property of the body.

For instance, we write

document.body.scrollTop = 1000;

to get the body element with document.body.

We set its scrollTop property to 1000 to scroll 1000 pixels down.

Conclusion

To get and set the current web page scroll position with JavaScript, we set the scrollTop property of the body.

Leave a Reply

Your email address will not be published. Required fields are marked *