DOM:element.scrollLeft
From MDC
Contents |
[edit] Summary
scrollLeft gets or sets the number of pixels that an element's content is scrolled to the left.
[edit] Syntax and values
// Get the number of pixels scrolled var sLeft = element.scrollLeft;
sLeft is an integer representing the number of pixels that element has been scrolled to the left.
// Set the number of pixels scrolled element.scrollLeft = 10;
scrollLeft can be set to any integer value, however:
- If the element can't be scrolled (e.g. it has no overflow), scrollLeft is set to 0.
- If set to a value less than 0, scrollLeft is set to 0.
- If set to a value greater than the maximum that the content can be scrolled, scrollLeft is set to the maximum.
[edit] Example
<script type="text/javascript">
function doScrollLeft()
{
document.getElementById('aDiv').scrollLeft = 50;
}
</script>
<div id="aDiv"
style="width: 200px; height: 200px; overflow: scroll;"
>
<script type="text/javascript">
for (var i=0; i<100; ++i){
document.write(i + '<pre>-FooBar-FooBar-FooBar-FooBar-FooBar-FooBar<br>');
}
</script>
</div>
<br>
<input type="button" value="Scroll left 50"
onclick="doScrollLeft();">
[edit] Specification
DOM Level 0. Not part of any standard.