.scrollLeft()
Get the current horizontal position of the scroll bar for the first element in the set of matched elements.
Syntax
.scrollLeft()(getter)
Parameters
None
Return value
The horizontal scroll position in pixels.
Description
The horizontal scroll position is the number of pixels that are hidden from view to the left of the scrollable area.
If the scroll bar is at the very left, or if the element is not scrollable, this number will be 0.
<html>
<head>
<script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
alert($("div").scrollLeft());
});
</script>
<style>
div{
width:200px;
height:100px;
overflow:auto;
}
h1 { width:1000px;height:1000px; }
</style>
</head>
<body>
<body>
<div><h1>header 1</h1></div>
</body>
</html>
Syntax
.scrollLeft(value) (setter)
Set the current horizontal position of the scroll bar for each of the set of matched elements.
Parameters
value
- An integer indicating the new position to set the scroll bar to
Return value
The jQuery object, for chaining purposes
<html>
<head>
<script src="http://java2s.com/Book/JavaScriptDemo/jQuery/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div").scrollLeft(300);
});
</script>
<style>
div{
width:200px;
height:100px;
overflow:auto;
}
h1 { width:1000px;height:1000px; }
</style>
</head>
<body>
<body>
<div><h1>header 1</h1></div>
</body>
</html>
Home
JavaScript Book
jQuery
JavaScript Book
jQuery
DOM:
- jQuery DOM
- $("html tags"):generate code with the jQuery wrapper function.
- .add()
- .addClass()
- .after()
- .andSelf()
- .append()
- .appendTo()
- .attr()
- .before()
- .children()
- .clone()
- .closest()
- .contents()
- .css()
- .detach()
- .filter()
- .first()
- .get()
- .has()
- .hasClass()
- .height()
- .html()
- .index()
- .innerHeight()
- .innerWidth()
- .insertAfter()
- .insertBefore()
- .is()
- .last()
- .map()
- .next()
- .nextAll()
- .nextUntil()
- .not()
- .offset()
- .offsetParent()
- .outerHeight()
- .outerWidth()
- .parent()
- .parents()
- .parentsUntil()
- .position()
- .prepend()
- .prependTo()
- .prev()
- .prevAll()
- .prevUntil()
- .remove()
- .removeClass()
- .removeAttr()
- .replaceAll()
- .replaceWith()
- .siblings()
- .scrollLeft()
- .scrollTop()
- .slice()
- .text()
- .toArray()
- .toggleClass()
- .unwrap()
- .val()
- .wrap()
- .wrapAll()
- .wrapInner()
- .width()