Categories
JavaScript Answers

How to get the max value of scrollLeft with JavaScript?

Spread the love

Sometimes, we want to get the max value of scrollLeft with JavaScript.

In this article, we’ll look at how to get the max value of scrollLeft with JavaScript.

How to get the max value of scrollLeft with JavaScript?

To get the max value of scrollLeft with JavaScript, we can use the scrollWidth and clientWidth propeties.

For instance, we write

const maxScrollLeft = element.scrollWidth - element.clientWidth;

to subtract the element‘s scrollWidth value by its clientWidth value.

Then we get the max value of scrollLeft.

Conclusion

To get the max value of scrollLeft with JavaScript, we can use the scrollWidth and clientWidth propeties.

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 *