English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
scrollTopThe property sets or returns the number of pixels the element content is scrolled vertically.
The scrollTop value of the element is the measurement from the top of the element to the topmost visible content. When the element's content does not generate a vertical scrollbar, its scrollTop value is 0.
UsingscrollLeftThe property sets or returns the number of pixels the element content is scrolled to the left (horizontally).
Return scrollTop property:
element.scrollTop
Set scrollTop property:
element.scrollTop = pixels
var elem = document.getElementById("container"); var x = elem.scrollLeft; var y = elem.scrollTop;Test and See‹/›
All browsers fully support the scrollTop property:
Property | |||||
scrollTop | Yes | Yes | Yes | Yes | Yes |
Value | Description |
---|---|
pixels | Specify the number of pixels the content of the element is scrolled vertically |
Return Value: | A number representing the number of pixels the content of the element has been scrolled vertically |
---|---|
DOM Version: | CSS Object Model (CSSOM) |
Vertical scroll content of DIV50px:
document.getElementById(').container').scrollTop += 50;Test and See‹/›
Vertical scroll content of BODY100 pixels:
var body = document.body;// For Safari var html = document.documentElement; // Chrome, Firefox, IE and Opera body.scrollTop += 100; html.scrollTop += 100;Test and See‹/›
HTML DOM Reference:scrollLeft property