scrollTop与scrollLeft

本文详细介绍了scrollTop与scrollLeft属性的使用方法,包括其语法、行为特性及应用场景。scrollTop用于获取或设置元素内容向上滚动的像素数,而scrollLeft则用于处理水平滚动。文章还解释了当元素不可滚动或滚动值超出范围时的处理方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

Image:BirmanCat.jpgAll 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

Image:scrollTop.png

详述
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值