Categories
JavaScript Answers

How to get the scroll position of div with “overflow: auto” with JavaScript?

Spread the love

Sometimes, we want to get the scroll position of div with "overflow: auto" with JavaScript.

In this article, we’ll look at how to get the scroll position of div with "overflow: auto" with JavaScript.

How to get the scroll position of div with "overflow: auto" with JavaScript?

To get the scroll position of div with "overflow: auto" with JavaScript, we use the scrollTop property.

For instance, we write

const scrollTop = document.getElementById("box").scrollTop;

to select the scrollable div with getElementById.

Then we get its scroll position with scrollTop.

Conclusion

To get the scroll position of div with "overflow: auto" with JavaScript, we use the scrollTop property.

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 *