jQuery scrollTop()Method

jQuery HTML/CSS 方法jQuery HTML/CSS Methods

Examples

Return the vertical scrollbar position of a <div> element:

$("button").click(function(){ alert($("div").scrollTop()); });

Try it yourself »

Definition and Usage

The scrollTop() method sets or returns the vertical scrollbar position of the selected elements.

Tip:When the scrollbar is at the top, the position is 0.

When used to return the position:
This method returns the vertical position of the scrollbar of the first matched element.

When used to set the position:
This method sets the vertical position of the scrollbar for all matched elements.


Syntax

Return the vertical scrollbar position:

$(selector).scrollTop()

Set the vertical scrollbar position:

$(selector).scrollTop(position)

Parameter Description
position Specifies the vertical scrollbar position in pixels.


实例

More Examples

Set the vertical scrollbar position
How to set the vertical scrollbar position for an element.


jQuery HTML/CSS 方法jQuery HTML/CSS Methods

Other Extensions