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.