Element.scrollLeft

  • Revision slug: DOM/element.scrollLeft
  • Revision title: element.scrollLeft
  • Revision id: 69973
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment clean up; 4 words removed

Revision Content

{{ DomRef() }}

Summary

scrollLeft gets or sets the number of pixels that an element's content is scrolled to the left.

Note that if the element's direction is 'rtl' (right-to-left) then scrollLeft is zero when the scrollbar is at its rightmost position (at start of the scrolled content) and then increasingly negative as you scroll towards the end of the content.

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 (greater than 0 for right-to-left elements), 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.

Example

 

Specification

{{ DOM0() }}

References

{{ MSDN("ms534617", "scrollLeft Property") }}

{{ languages( { "fr": "fr/DOM/element.scrollLeft", "pl": "pl/DOM/element.scrollLeft" } ) }}

Revision Source

<p>{{ DomRef() }}</p>
<h3 name="Summary">Summary</h3>
<p><code>scrollLeft</code> gets or sets the number of pixels that an element's content is scrolled to the left.</p>
<p>Note that if the element's <a href="/en/CSS/direction" title="https://developer.mozilla.org/en/CSS/direction">direction</a> is 'rtl' (right-to-left) then <code>scrollLeft</code> is zero when the scrollbar is at its rightmost position (at start of the scrolled content) and then increasingly negative as you scroll towards the end of the content.</p>
<h3 name="Syntax_and_values">Syntax and values</h3>
<pre class="eval">// Get the number of pixels scrolled
var <var>sLeft</var> = <var>element</var>.scrollLeft;
</pre>
<p><var>sLeft</var> is an integer representing the number of pixels that <var>element</var> has been scrolled to the left.</p>
<pre class="eval">// Set the number of pixels scrolled
<var>element</var>.scrollLeft = 10;
</pre>
<p><code>scrollLeft</code> can be set to any integer value, however:</p>
<ul> <li>If the element can't be scrolled (e.g. it has no overflow), <code>scrollLeft</code> is set to 0.</li> <li>If set to a value less than 0 (greater than 0 for right-to-left elements), <code>scrollLeft</code> is set to 0.</li> <li>If set to a value greater than the maximum that the content can be scrolled, <code>scrollLeft</code> is set to the maximum.</li>
</ul>
<h3 name="Example">Example</h3>
<pre> </pre>
<h3 name="Specification">Specification</h3>
<p>{{ DOM0() }}</p>
<h3 name="References">References</h3>
<p>{{ MSDN("ms534617", "scrollLeft Property") }}</p>
<p>{{ languages( { "fr": "fr/DOM/element.scrollLeft", "pl": "pl/DOM/element.scrollLeft" } ) }}</p>
Revert to this revision