scrollTop property is used to get the number of pixels that are scrolled vertically.
If the element is not scrollable or when it doesn't contain any scroll bar, it returns 0.
var elem = element.scrollTop;
Example - Getting the scrollTop of an element
- In the above example, when the button is clicked fun_name() function is called.
- Using the scrollTop property, when the content is scrolled to the top, it retrieves the total pixels has been scrolled and displaying it (alert(attr.scrollTop)).