jQuery Tutorial Tutorials - jQuery .scrollTop() method

jQuery .scrollTop() method

The .scrollTop() method in jQuery is used to get/set the vertical position position of the scroll bar for the matched element.

jQuery .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

example

Get the vertical position of the scroll bar for the second div.

var div = $("div:eq(1)");
var scrollTop = div.scrollTop();
console.log(scrollTop);

Try now

.scrollTop(value)

Set the vertical position of the scroll bar for each matched element.
value is new position to set the scroll bar to.

example

Set the scrollTop of a div to 50px.

$('div').scrollTop(50);

Try now

Date:2019-08-20 16:11:40 From:www.Lautturi.com author:Lautturi