이 글은 편집 검토가 필요합니다. 도울을 줄 수 있는 방법을 살펴보세요.
이 문서는 아직 자원 봉사자들이 한국어로 번역하지 않았습니다. 함께 해서 번역을 마치도록 도와 주세요!
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 to0
. - If set to a value less than
0
,scrollTop
is set to0
. - 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
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) |