.scrollLeft()
Categories: Style Properties | CSS | Offset
.scrollLeft()Returns: Integer
Description: Get the current horizontal position of the scroll bar for the first element in the set of matched elements.
-
.scrollLeft()
version added: 1.0
The horizontal scroll position is the same as the number of pixels that are hidden from view above the scrollable area. If the scroll bar is at the very left, or if the element is not scrollable, this number will be 0
.
Note:
.scrollLeft()
, when called directly or animated as a property using.animate()
will not work if the element(s) it is being applied to are hidden.
-
Get the scrollLeft of a paragraph.
HTML:
<p>Hello</p><p></p>
CSS:
p { margin:10px;padding:5px;border:2px solid #666; }
Code:
var p = $("p:first"); $("p:last").text( "scrollLeft:" + p.scrollLeft() );
.scrollLeft( value )Returns: jQuery
Description: Set the current horizontal position of the scroll bar for each of the set of matched elements.
-
.scrollLeft( value )
version added: 1.0value An integer indicating the new position to set the scroll bar to.
The horizontal scroll position is the same as the number of pixels that are hidden from view above the scrollable area. Setting the scrollLeft
positions the horizontal scroll of each matched element.
-
Set the scrollLeft of a div.
HTML:
<div class="demo"><h1>lalala</h1><p>Hello</p></div>
CSS:
div.demo { background:#CCCCCC none repeat scroll 0 0; border:3px solid #666666; margin:5px; padding:5px; position:relative; width:200px; height:100px; overflow:auto; } p { margin:10px;padding:5px;border:2px solid #666;width:1000px;height:1000px; }
Code:
$("div.demo").scrollLeft(300);