scrollLeft property in javascript
scrollLeft property is used to get the number of pixels that are scrolled from left.
If the elements direction is rtl (right-to-left), it returns 0.
Syntax
var elem = element.scrollLeft;
Example Explanation
- In the above example, when the button is clicked fun_name() function is called.
- In the Javascript function, first we are getting the element (document.getElementById("idP")) and storing in attr variable.
- Using the scrollLeft property, when the content is scrolled to the left, it retrieves the total pixels of the scrolled area and displaying it (alert(attr.scrollLeft);).