scrollTop与scrollLeft
1).scrollTop
总结
scrollTop gets or sets the number of pixels that the content of an element is scrolled upward.(这句话不知道怎么翻译,我相信看原文解释更清楚)
语法
// 获取元素被滚动到上方的值
var intElemScrollTop = element.scrollTop;
// 设置scrollTop的值为intValue
element.scrollTop = intValue;
1).若元素不可滚动,则scrollTop值为0;
2).若元素的scrollTop值设置为小于0,则scrollTop被重置为0;
3).若元素的scrollTop值设置为大于内容的最大可滚动的宽度,则scrollTop被重置为最大值.
描述
一个元素的scrollTop值是指元素的顶部到它可见内容的最高点之间的距离.当元素的内容没有生成垂直滚动条,则它的scrollTop的值默认为0.
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.
例子
padding-top
Gentle, individualistic and very loyal, Birman cats fall between Siamese and Persian in character. If you admire cats that are non aggressive, that enjoy being with humans and tend to be on the quiet side, you may well find that Birman cats are just the felines for you.
All Birmans have colorpointed features, dark coloration of the face, ears, legs and tail.
Cat image and text coming fromwww.best-cat-art.com
padding-bottom
Left
Top
Right
Bottom
margin-top
margin-bottom
border-top
border-bottom
详述
scrollTop是MSIE DHTML对象模型的内容,并且在Gecko引擎中得到支持.scrollTop现在是W3C CSS工作组的草案的内容.
同理可理解scrollLeft属性
https://developer.mozilla.org/en/DOM/element.scrollLeft
原文:
https://developer.mozilla.org/en/DOM/element.scrollTop
相关阅读
MSDN's scrollTop definition
MSDN's scrollLeft Property
MSDN's Measuring Element Dimension and Location
W3C Draft CSSOM View Module