jQuery CSS Operation - scrollTop() Method
Example
Set the vertical offset of the scroll bar in the <div> element:
$(".btn1").click(function(){ $("div").scrollLeft(100); });
Definition and usage
The scrollTop() method returns or sets the vertical position of the scroll bar for matched elements.
Scroll top offset refers to the offset of the scroll bar from its top.
If this method is not set with a parameter, it returns the relative offset from the top of the scroll bar, in pixels.
Syntax
$(selector).scrollTop(offset)
Parameters | Description |
---|---|
offset | Optional. Specifies the relative offset from the top of the scroll bar, in pixels. |
Tips and notes
Note:This method is effective for both visible and invisible elements.
Note:When used to get a value, this method only returns the scroll top offset of the first matched element.
Note:When used to set a value, this method sets the scroll top offset for all matched elements.
More examples
- Get the current scroll top offset
- Obtain the scroll top offset using the scrollTop() method.