top、postop、scrolltop、scrollHeight、offsetHeight
网页可见区域宽:document.body.clientWidth;
网页可见区域高:document.body.clientHeight;
网页可见区域高:document.body.offsetWeight:
网页可见区域高:document.body.offsetHeight;
网页正文全文宽:document.body.scrollWidth;
网页正文全文高:document.body.scrollHeight;
网页被卷去的高:document.body.scrollTop;
网页被卷去的左:document.body.scrollLeft;
网页正文部分上:window.screenTop;
网页正文部分左:window.screenLeft;
屏幕分辨率的高:window.screen.height;
屏幕分辨率的宽:window.screen.width;
屏幕可用工作区高度:window.screen.availHeight;
屏幕可用工作区宽度:window.screen.availWidth;
scrollWidth
是对象的实际内容的宽,不包边线宽度,会随对象中内容的多少改变(内容多了可能会改变对象的实际宽度)
clientWidth
是对象可见的宽度,不包滚动条等边线,会随窗口的显示大小改变。
offsetWidth
是对象的可见宽度,包滚动条等边线,会随窗口的显示大小改变。
------------------------------------------------
一个scrollWidth和clientWidth的例子:
<html>
<head>
<title>77.htm文件</title>
</head>
<body>
<textarea wrap="off" οnfοcus="alert('scrollWidth:'+this.scrollWidth+'\n clientWidth:'+this.clientWidth);"></textarea>
</body>
</html>
在文本框内输入内容,当横向滚动条没出来前scrollWidth和clientWidth的值是一样的。
当一行内容超出文本框的宽度,就有横向滚动条出来了,scrollWidth的值就变了。
scrollWidth是对象实际内容的宽度。
clientWidth是对象看到的宽度(不含边线),这个例子里不会改变。
-----------------------------------------------
一个clientWidth和offsetWidth的例子:
<html>
<head>
<title>77.htm文件</title>
</head>
<body>
<textarea wrap="off" οnfοcus="alert('offsetWidth:'+this.offsetWidth+'\n clientWidth:'+this.clientWidth);"></textarea>
</body>
</html>
offsetWidth的值总是比clientWidth的值打
clientWidth是对象看到的宽度(不含边线)
offsetWidth是对象看到的宽度(含边线,如滚动条的占用的宽)
top、postop、scrolltop、scrollHeight、offsetHeight
1. top
此属性仅仅在对象的定位(position)属性被设置时可用。否则,此属性设置会被忽略。
<p style="background-color:silver; position:absolute; top:-5px;">测试top</p>
</div>
上面是一个段落P包含在一个DIV内,可以看到P的top设置为-5px后,它的上边距超过了容器DIV的上边距,超过的这段距离就是设置的5px。
需要注意的是,DIV和P这一对包含元素,都需要设置position为absolute才能得到想要的结果,假如父元素不设置,则子元素的参照将是更上层定义过position的元素,直到整个文档;
2. posTop
posTop的数值其实和top是一样的,但区别在于,top固定了元素单位为px,而posTop只是一个数值(这一点可以通过alert("top="+id.style.top)和alert("posTop="+id.style.posTop)来证明),因此一般使用posTop来进行运算。
<p id="test" style="background-color:silver; position:absolute;">测试posTop</p>
</div>
<script>
test.style.posTop = 15+8;
alert("top="+test.style.top);
alert("posTop="+test.style.posTop);
</script>
无论你使用top或posTop来赋值,最后的结果都是一致的
3. scrollTop
<p style="background-color:red;">
别再做情人 做只猫 做只狗 不做情人 做只宠物至少可爱迷人 和你相交不浅无谓明日会被你憎</p>
</div>
<script>
container.scrollTop = 12;
</script>
这一段文本在这个100*100的DIV内无法完全显示,所以设置了overflow为auto,它会出现一个上下方向的滑动框,假如没有设置id.scrollTop属性的话,默认情况下滑块位置在顶端。而设置了scrollTop值为12后,滑块的位置改变了,默认显示是卷过了12个象素的文本。如果设置overflow为hidden,则将会无法显示顶部12个象素的文本。
注意设置方式是id.scrollTop,而不是id.style.scrollTop。
4. scrollHeight 与 offsetHeight
offsetHeight是自身元素的高度,scrollHeight是 自身元素的高度+隐藏元素的高度。
<p style="background-color:red; height:250px; ">
别再做情人 做只猫 做只狗 不做情人 做只宠物至少可爱迷人 和你相交不浅无谓明日会被你憎</p>
</div>
<script>
alert(container.offsetHeight);
alert(container.scrollHeight);
</script>
将依次输出100,250。因为已经指定了元素的height为100px,所以offsetHeight始终为100px;内部元素为250px,而容器元素只有100px,那么还有150px的内容它无法显示出来,但它却是实际存在的,所以scrollHeight值为100+150=250。
转载于:https://www.cnblogs.com/aaa6818162/archive/2009/10/30/1592855.html
top、postop、scrolltop、scrollHeight、offsetHeight相关推荐
- clientHeight、offsetHeight、scrollHeight、scrollTop
由于长时间对clientHeight.offsetHeight.scrollHeight.scrollTop这几个js-dom不理解,处于半迷糊状态,现在就仔仔细细实验整理一波,希望能做个总结,方便以 ...
- scrollHeight、clientHeight、offsetHeight、scrollTop等的定义以及图解
开发中经常遇到使用scrollHeight.scrollTop.clientHeight.offsetHeight等的情况,网上有众多关于这些属性的解释,但是并不全面和直观,现在将这些属性结合图例整理 ...
- CSS中clientHeight、offsetHeight、scrollHeight、scrollTop、scrollTo几者的区别和关联
怎么区分clientHeight.offsetHeight.scrollHeight.scrollTo.scrollTop呢,我们通过下面的示例来搞清楚. 现有如下示例: 对应css为 .div {w ...
- Js——ScrollTop、ScrollHeight、ClientHeight、OffsetHeight汇总
一直对ScrollTop.ScrollHeight.ClientHeight.OffsetHeight这些内容傻傻分不清楚,今天整体下. scrollHeight scrollHeight含有scro ...
- scrollHeight、clientHeight、offsetHeight、 scrollTop
由于需要实现下拉分页加载,所以对scrollHeight.clientHeight.offsetHeight. scrollTop做些简单总结. 一.scrollHeight.clientHeight ...
- html5 scrollheight,JavaScript之scrollTop、scrollHeight、offsetTop、offsetHeight等属性学习笔记...
全文参考:https://github.com/iuap-design/blog/issues/38 .MDN clientHeight,只读 clientHeight可以用公式 CSS height ...
- js中 scrollHeight、clientHeight、scrollTop的理解
前段时间,自己手写了一个滚动触底加载数据的功能.当时由于时间紧迫,所以也就只是在网上找了一段代码贴上去.也没有很深入的去研究.今天有空,所以自己特意去研究了下它的原理. 滚动触底加载数据,之前我也有写 ...
- html 滚动条 scrolltop scrollheight,浅谈JavaScript中scrollTop、scrollHeight、offsetTop、offsetHeight...
浅谈JavaScript中scrollTop.scrollHeight.offsetTop.offsetHeight 发布时间:2020-07-17 09:27:20 来源:亿速云 阅读:223 作者 ...
- html 滚动条 scrolltop scrollheight,JavaScript之scrollTop、scrollHeight、offsetTop、offsetHeight等属性学习笔记...
全文参考:https://github.com/iuap-design/blog/issues/38 .MDN clientHeight,只读 clientHeight可以用公式 CSS height ...
最新文章
- Python3中的内置函数
- 在博文顶部添加文章字数及阅读时间信息:阅读本文需要xx分钟
- mysql英文介绍_每日科技英文48: MySQL C API简介
- bilibili有电脑版吗_哪个手机便签软件有电脑版?有跨平台的桌面便签软件吗 - 学显...
- 再过十年,电脑游戏会被手机游戏完全取代吗?
- iOS关于代理的理解
- 7-8 黑洞数 (20 分)
- python分数计算器_python计算器实现过程
- 使用BindingSource连接数据库
- 数据分析工具urule
- 计算机输入法切换用户登录,电脑切换不出来输入法,教您解决切换输入法的问题...
- ubantu 终端屏幕查找字符串
- 给女朋友道歉的java代码_有关于向女朋友道歉的经典句子
- 今年能不能回家全靠这3个抢票工具了|2022版
- elasticsearch服务自动断掉
- SBUS转485增程方案,SBUS控制远程机器人方案
- power bi 雷达图_星载雷达与C波段地基雷达数据一致性个例分析 | 新文速递
- 51单片机c语言工作手册,51单片机C语言编程手册
- 图形图像处理案例3——爱心螺旋画,双心螺旋画
- Python爬虫之四:使用BeautifulSoup爬取微博热搜
热门文章
- 流式计算的代表:Storm、Flink、Spark Streaming
- 天池 在线编程 放小球(动态规划)
- LeetCode 354. 俄罗斯套娃信封问题(最长上升子序 DP/二分查找)
- linux下实现内存监视,shell脚本来监视Linux上的内存使用情况
- php aura,AuraPHP路由器没有拿起参数
- erp系统方案书_门禁系统方案书
- bigdecimal 保留两位小数_一起聊聊小数的储存和运算
- 线性代数应该这样讲(二)
- 函数式编程在Redux/React中的应用
- 论文浅尝 | 知识图谱中的链接预测:一种基于层次约束的方法