jQuery Tutorial Tutorials - jQuery .scrollLeft() method

jQuery .scrollLeft() method

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

jQuery .scrollLeft() method Syntax

.scrollLeft()
.scrollLeft(value)

.scrollLeft()

get the horizontal position of the scroll bar for the first matched element. If the element is not scrollable, this number will be 0

example

Get the scrollLeft of the second div.

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

Try now

.scrollLeft(value)

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

example

Set the scrollLeft of a div to 50px.

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

Try now

Date:2019-08-20 16:10:46 From:www.Lautturi.com author:Lautturi