Categories
JavaScript Answers

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

Spread the love

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

For instance, we write

document.documentElement.scrollTop = document.body.scrollTop = 1000;

to set the scrollTop property of the body element to 1000 to scroll 1000px down.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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