.scrollTop()
methodThe .scrollTop()
method in jQuery is used to get/set the vertical position position of the scroll bar for the matched element.
.scrollTop()
method Syntax.scrollTop() .scrollTop(value)
.scrollTop()
Get the vertical position of the scroll bar for the first matched element. If the element is not scrollable, this number will be 0
Get the vertical position of the scroll bar for the second div.
var div = $("div:eq(1)"); var scrollTop = div.scrollTop(); console.log(scrollTop);
.scrollTop(value)
Set the vertical position of the scroll bar for each matched element.
value
is new position to set the scroll bar to.
Set the scrollTop of a div to 50px.
$('div').scrollTop(50);