offsetHeight、scrollHeight、clientHeight、height
对这几项进行彻底研究。
第一步:纯净div,没有margin,padding,border,height设置为200px。
添加滚动条,overflow:scroll,结果div的高度被压缩,因为被滚动条占用17px(滚动条的高度为17px)。

加入滚动条前:
- scrollHeight=200px
- offsetHeight=200px
加入滚动条后:
- scrollHeight=183px=(内容高度200px-滚动条17px) (说明scrollHeight已经不包括滚动条的高度)
- offsetHeight=200px
第二步:将div加上20px的padding

加上padding之后:
- scrollHeight=(内容高度200px+上下padding40px-滚动条17px)=223px(说明scrollheight包括padding,不包括下滚动条的高度。
结论:滚动高度可以理解为和滚动条平行的那段距离,显然,border和margin都不和滚动条平行,所以,border和margin都不算在滚动高度内) - offsetHeight=200px+上下padding=240px (说明offsetHeight就是整个div的最终高度)
结论:offsetHeight直观理解是眼睛能看的到的整个高度,包括(如果有的话):滚动条+内容+padding+border,margin不可见,所以不算在内)
内容超长的情形:
- scrollHeight的值就为内容展平的高度+padding,可以想像成内容展平的高度。
结论:
- scrollHeight=内容高度 + (上下)padding - 底部滚动条17px(如果有)(可变)
- offsetHeight=整个可见高度(固定)
- clientHeight=可见内容高度+(上下)padding(固定)
offsetHeight、scrollHeight、clientHeight、height的更多相关文章
- 【日常总结】scrollTop、scrollHeight与clientHeight的重要关系
前言 在做一个需求的时候涉及懒加载,百度了一下,发现scrollTop.scrollHeight与clientHeight这三个元素起到了重要作用,以前做过类似demo但是时间过太久忘记了,现在已经完 ...
- scrollTop、scrollHeight与clientHeight
MDN上概念 scrollTop:获取或设置一个元素的内容垂直滚动的像素数. scrollHeight:一个元素内容高度的度量,包括由于溢出导致的视图中不可见内容. clientHeight:元素内部 ...
- height、clientHeight、offsetHeight、scrollHeight、height()、 innerHeight()、outerHeight()等的区别
1.height height是css属性,这个属性定义元素内容区的高度,在内容区外面可以增加内边距.边框和外边距. 当 box-sizing: content-box 时,高度应用到元素的内容框. ...
- 关于height、offsetheight、clientheight、scrollheight、innerheight、outerheight的区别一览
平时,不管在pc端页面还是移动端页面,因为我们一般很少会设置某个块的的高度,但是呢,我有时候有需要取到这些高度以便于我们方便进行判断和下一步的编写.一般这个时候我都是直接的获取一个块的高度.heigh ...
- jquery 对象的 height、innerHeight、outerHeight 的区别以及DOM 元素的 clientHeight、offsetHeight、scrollHeight、offsetTop、scrollTop
前言:jquery 对象的 height.innerHeight.outerHeight,还有 DOM 元素的 clientHeight.offsetHeight.scrollHeight.offse ...
- Height、clientHeight、scrollHeight、offsetHeight 、scrollTop、offsetTop
Height 返回当前文档中的<body>元素的高度 clientHeight 对于没有定义CSS或者内联布局盒子的元素为0,否则,它是元素内部的高度(单位像素),包含内边距,但不包括水平 ...
- 各种高度的区别及height、clientHeight、scrollHeight、offsetHeight的区分
1.height.clientHeight.scrollHeight.offsetHeight 我们来实现test中的onclick事件 function justAtest() { ...
- height、clientHeight、scrollHeight、offsetHeight区别
转自 http://www.cnblogs.com/yuteng/articles/1894578.html 我们来实现test中的onclick事件 function justAtest() ...
- 四种浏览器对 clientHeight、offsetHeight、scrollHeight、clientWidth、offsetWidth 和 scrollWidth 的解释差异
网页可见区域宽:document.body.clientWidth 网页可见区域高:document.body.clientHeight 网页可见区域宽:document.body.offsetWid ...
- 详解clientHeight、offsetHeight、scrollHeight
关于clientHeight.offsetHeight.scrollHeight window.screen.availWidth 返回当前屏幕宽度(空白空间) window.screen.av ...
随机推荐
- HTTP协议介绍(POST、GET、Content-Type)
什么是HTTP?超文本传输协议(HyperText Transfer Protocol -- HTTP)是一个设计来使客户端和服务器顺利进行通讯的协议.HTTP/1.1 协议规定的 HTTP 请求方法 ...
- go语言中的函数
package main; import "fmt" func main() { a, b, c := A(1, 2, 3); fmt.Println(a, b, c); //调用 ...
- centos7下的FastDFS5.09的安装与使用
FastDFS是一款开源的轻量级分布式文件系统,纯C实现,支持Linux.FreeBSD等Unix系统. 类google FS,不是通用的文件系统,只能通过专有API访问. FastDFS服务端有两种 ...
- ajax添加header信息
$.ajax({url:"xxx",async:true,dataType:"json",contentType:"application/json& ...
- OnActionExecuting验证用户登录
代码 using Common; using Service; using Service.IService; using System; using System.Collections.Gener ...
- 使用clear来清除localStorage保存对象的全部数据
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- Liunjx 文件
cat命令的用途是连接文件或标准输入并打印.这个命令常用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示,它常与重定向符号配合使用. 1.命令格式: cat [选项] [文件] ...
- 去掉easyui datagrid内部虚线的方式。
去掉easyui datagrid内部虚线的方式.easyui datagrid的样式是统一写在样式文件中的,如果想要统一替换可以找对应的datagird样式文件中的以下部分.如果想要改 ...
- 关于java.io.IOException: HADOOP_HOME or hadoop.home.dir are not set.的问题
报错如下: 300 [main] DEBUG org.apache.hadoop.util.Shell - Failed to detect a valid hadoop home directory ...
- java8 数据结构的改变(一)
在JDK1.6,JDK1.7中,HashMap采用数组+链表实现,即使用链表处理冲突,同一hash值的链表都存储在一个链表里.但是当数组中一个位置上的元素较多,即hash值相等的元素较多时,通过key ...