Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

This article needs an editorial review. How you can help.

Naši dobrovolníci ještě tento článek do jazyka Čeština nepřeložili. Přidejte se a pomozte nám tuto práci dokončit!

The Element.scrollTop property gets or sets the number of pixels that the content of an element is scrolled upward. An element's scrollTop is a measurement of the distance of an element's top to its topmost visible content. When an element content does not generate a vertical scrollbar, then its scrollTop value defaults to 0.

Syntax

// Get the number of pixels scrolled
var  intElemScrollTop = someElement.scrollTop;

After running this code, intElemScrollTop is an integer corresponding to number of pixels that the element's content has been scrolled upward.

// Set the number of pixels scrolled
element.scrollTop = intValue;

scrollTop can be set to any integer value, with certain caveats:

  • If the element can't be scrolled (e.g. it has no overflow or if the element is non-scrollable), scrollTop is set to 0.
  • If set to a value less than 0, scrollTop is set to 0.
  • If set to a value greater than the maximum that the content can be scrolled, scrollTop is set to the maximum.

Example

padding-top

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

padding-bottom

Left Top Right Bottom margin-top margin-bottom border-top border-bottom

Specifications

Specification Status Comment
CSS Object Model (CSSOM) View Module
The definition of 'scrollTop' in that specification.
Working Draft  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes) ? ? ? ?
Feature Android Android Webview Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support ? (Yes) ? ? ? ? ? (Yes)

References

Štítky a přispěvatelé do dokumentace

 Poslední aktualizace od: sbussard,