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
LeftTopRightBottommargin-topmargin-bottomborder-topborder-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 definitionMSDN's scrollLeft PropertyMSDN's Measuring Element Dimension and LocationW3C Draft CSSOM View Module
分享到:
相关推荐
官方文档的解释有点含糊,其实换个角度就很容易理解了,scrollTop获取的是内部元素超出外部容器的高度。例如:$('window').scrollTop()获取的就是当前这个页面超出窗口最上端的高度,scrollLeft与此同理
图示offsetWidth、clientWidth、scrollWidth、scrollTop、scrollLeft等属性,对于一些页面的控制很有帮助。
网页被卷去的高: document.body.scrollTop; 网页被卷去的左: document.body.scrollLeft; 网页正文部分上: window.screenTop; 网页正文部分左: window.screenLeft; 屏幕分辨率的高: window.screen.height; 屏幕...
js中scrollHeight,scrollWidth,scrollLeft,scrolltop等差别介绍,需要的朋友可以看看
scrollLeft,scrollTop等等详解[定义].pdf
我使用scrollTop / scrollLeft dom属性,因此它应该与任何其他滚动插件配合使用。依存关系jQuery 1.4以上jQuery UI 1.8.16(核心,小部件工厂,可拖动,位置) jQuery mousewheel插件-版权所有(c)2010 Brandon ...
对offsetLet,offsetTop,scrollLeft,scrollTop几个方法的理解,
代码如下:<!DOCTYPE html PUBLIC “-//W3C... <head> <title>jQuery的位置函数(offset(),innerWidth(),innerHeight(),outerWidth(),outerHeight(),scrollTop(),scrollLeft())小应用</title> <s
弹窗在谷歌浏览器chrome下的位置跟在别的浏览器下不一样,接下来介绍下scrollLeft,scrollTop的浏览器兼容性,感兴趣的你可以参考下哈
2、scrollTop/scrollLeft:滚动条卷去的高度/宽度(这两个属性是唯一“可读写”的属性) box.scrollTop = 0 // 直接回到容器的顶部 我们的scrollTop的值是存在边界值(最大和最小值),我们设置的值比最小值小或者比...
不是针对可见客户区的,所以在拖拽的过程中不得不考虑被卷走的部分,因为网页文档可能很大,无论宽度还是高度都可能大于客户区,等于客户区大小就很好处理,大于的话就得考虑scrollTop和scrollLeft,否则div会跟鼠标...
主要介绍了vue项目设置scrollTop不起作用(总结),小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
做页面的时候可能会用到位置固定的层,读取 document.body.scrollTop 来设置层的位置,像这样: [removed] = function (){ var oFix = document.getElementById(“divfix”); oFix.style.top = document.body....
这里的示例演示了一个table页面,并固定表头或者列头,以达到excel冻结列的效果,主要使用的js的scrollTop,scrollLeft. 一.js中scrollTop及scrollLeft的使用说明 scrollTop指的是“元素中的内容”超出“元素上边界”的...
推翻与框架无关的overflow: auto用于响应设计的overflow: auto polyfill。... 本机的scrollTop和scrollLeft:使用本机JavaScript scrollTop和scrollLeft属性,而不是使用CSS属性来模拟滚动。 这意味着您可以使用
scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离 scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离 scrollWidth:获取对象的滚动宽度 offsetHeight:获取对象相...