English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
scrollLeftThe property sets or returns the number of pixels the element content scrolls to the left (horizontal direction).
Note:If the element'sdirection(direction)Isrtl(from right to left), then when the scrollbar is at its farthest right position (at the beginning of the scrolling content), scrollLeft is0and then scrolling to the end of the content, scrollLeft gradually becomes negative.
UsingscrollTopThe property can set or return the number of pixels the element content (vertical) scrolls to the top.
Return the scrollLeft property:
element.scrollLeft
Set the scrollLeft property:
element.scrollLeft = pixels
var elem = document.getElementById("container"); var x = elem.scrollLeft; var y = elem.scrollTop;Test and See‹/›
All browsers fully support the scrollLeft property:
Property | |||||
scrollLeft | Is | Is | Is | Is | Is |
Value | Description |
---|---|
pixels | Specify the number of pixels the element content is scrolled horizontally |
Return Value: | A number representing the number of pixels the element content has been scrolled horizontally |
---|---|
DOM Version: | CSS Object Model (CSSOM) |
Scroll the content of the DIV horizontally20 pixels:
document.getElementById('container').scrollLeft += 20;Test and See‹/›
Scroll the content of the BODY horizontally100 pixels:
var body = document.body;// For Safari var html = document.documentElement; // Chrome, Firefox, IE and Opera body.scrollLeft += 100; html.scrollLeft += 100;Test and See‹/›
HTML DOM Reference:scrollTop property