jQuery scrollLeft()Method

jQuery HTML/CSS 方法jQuery HTML/CSS Methods

Example

Return the horizontal scrollbar position of the <div> element:

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

Try it Yourself »

Definition and Usage

The scrollLeft() method sets or returns the horizontal scrollbar position of the selected elements.

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

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

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


Syntax

Return the horizontal scrollbar position:

$(selector).scrollLeft()

Set the horizontal scrollbar position:

$(selector).scrollLeft(position)

Parameters Description
position Specifies the horizontal scrollbar position in pixels.


实例

More Examples

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


jQuery HTML/CSS 方法jQuery HTML/CSS Methods

Other Extensions