开发中经常遇到使用scrollHeight、scrollTop、clientHeight、offsetHeight等的情况,网上有众多关于这些属性的解释,但是并不全面和直观,现在将这些属性结合图例整理如下,方便日后查阅:

DOM元素对象

clientHeight 返回当前元素在页面上的可视高度(包括padding;不包括border、margin、滚动条高度) 单位px
clientWidth 返回当前元素在页面上的可视宽度(包括padding;不包括border、margin、滚动条宽度) 单位px
offsetHeight 返回当前元素在页面上的可视高度(包括padding、border、滚动条高度;不包括margin) 单位px
offsetWidth 返回当前元素在页面上的可视宽度(包括padding、border、滚动条宽度;不包括margin) 单位px
scrollHeight 返回当前整个元素的高度(包括带滚动条的隐蔽的地方) 单位px
scrollWidth 返回当前整个元素的宽度(包括带滚动条的隐蔽的地方) 单位px
scrollTop  clientHeight的顶部到scrollHeight顶部的高度 单位px
scrollLeft  clientWidth左边缘到offsetWidth左边缘的距离 单位px
offsetTop  指当前元素距离上方或上层元素的距离 单位px
offsetLeft  指当前元素距离左边或上层元素左边的距离 单位px

参考资料

http://www.runoob.com/jsref/dom-obj-all.html

https://www.jianshu.com/p/d267456ebc0d

scrollHeight、clientHeight、offsetHeight、scrollTop等的定义以及图解的更多相关文章

  1. 一起看看 scrollHeight,clientHeight,offsetHeight,scrollTop是个啥

    scrollHeight最终数值的组成: var scrollHeight = currentElementContent.height +currentElement.paddingTop+curr ...

  2. Height、clientHeight、scrollHeight、offsetHeight 、scrollTop、offsetTop

    Height 返回当前文档中的<body>元素的高度 clientHeight 对于没有定义CSS或者内联布局盒子的元素为0,否则,它是元素内部的高度(单位像素),包含内边距,但不包括水平 ...

  3. 转 top、postop、scrolltop、offsetTop、scrollHeight、offsetHeight、clientHeight

    1.top 此属性仅仅在对象的定位(position)属性被设置时可用.否则,此属性设置会被忽略. 复制代码 代码如下: <div style=" position:absolute; ...

  4. JS clientHeight,scrollHeight,offsetHeight,scrollTop,offsetTop概念

    JS滚动页面到某一位置时触发指定事件能够增强用户体验或是提高性能,其中使用最多的场景是加载更多,当鼠标滚动至页面下方时,自动加载下一页的内容.另一个常用的场景是当用户滚动至页面某一地方时,页面会给出提 ...

  5. 理解clientX、clientY、offsetLeft、event.offsetTop、offsetWidth、offsetHeight、clientWidth、clientHeight、scrollTop、scrollHeight

    一.clientX和clientY 事件发生时,鼠标距离浏览器的可视区域的X.Y轴的位置,不包含滚动条的区域的部分.就算是页面进行了滚动,鼠标的坐标值还是参考可视区域的. 二.offsetLeft和o ...

  6. top、postop、scrolltop、offsetTop、scrollHeight、offsetHeight、clientHeight

    1.top 此属性仅仅在对象的定位(position)属性被设置时可用.否则,此属性设置会被忽略 2.posTop posTop的数值其实和top是一样的,但区别在于,top固定了元素单位为px,而p ...

  7. 页面位置 top、postop、scrolltop、offsetTop、scrollHeight、offsetHeight、clientHe

    1.top 此属性仅仅在对象的定位(position)属性被设置时可用.否则,此属性设置会被忽略. 代码如下: <div style=" position:absolute; widt ...

  8. 各种高度的区别及height、clientHeight、scrollHeight、offsetHeight的区分

    1.height.clientHeight.scrollHeight.offsetHeight 我们来实现test中的onclick事件    function justAtest()    {    ...

  9. clientHeight ,offsetHeight,style.height,scrollHeight有区别与联系

    style.height 包括 元素的滚动条,不包括边框clientHeight 不包括元素的滚动条和边框,只有在没有元素的滚动条的情况下,style.height相等于clientHeightoff ...

随机推荐

  1. JS设计模式基础

    设计模式: 通过封装.继承.多态.组合等技术的反复使用,提炼出一些可重复使用的面向对象设计技巧. 1.多态(’做什么‘和’谁去做‘分开) 多态指同一个实体同时具有多种形式. 同一操作应用于不同的对象上 ...

  2. msdn List sort排序 IComparable 用法

    using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace Console ...

  3. oracle 存储过程 ,触发器练习

    /*以下代码是对emp表进行显示宽度设置 */col empno for 9999;col ename for a10;col job for a10;col mgr for 9999;col hir ...

  4. 关于同一线程两次调用EnterCriticalSection的测试

    #include "stdafx.h" #include <iostream> using namespace std; #include <windows.h& ...

  5. bbc mvn报错

    http://www.cnblogs.com/zhouyalei/archive/2011/11/30/2268606.html

  6. intellij jetBrains phpstorm/webstorm/IDEA 编辑器使用诀窍

    下载地址 https://www.jetbrains.com/products.html?fromMenu 主题/皮肤切换或下载:https://blog.csdn.net/smallxiannoti ...

  7. 把一个base64编码的图片绘制到canvas (canvas的图片在转成dataurl)

    把一个base64编码的图片绘制到canvas 需要引入jquery. <canvas id="myCanvas" width="800" height= ...

  8. Linux 系统 pptpd+radius+mysql 安装攻略

    分类: 原文地址:Linux 系统 pptpd+radius+mysql 安装攻略 作者:wfeng .你所需要的软件 内核最好能升级到2.6 如果你是centos的用户,可以通过yum update ...

  9. MongoDB GridFS最佳应用概述

    <MongoDB GridFS最佳应用概述> 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs GridFS是MongoDB数据库之上的一个简单 ...

  10. 静态资源打包:一个javescript 的src引用多个文件,一个link引用多个CSS文件

    疑惑描述: 查看了淘宝网的首页源文件,看到这样的一个特殊的 <script src="http://a.tbcdn.cn/??s/kissy/1.1.6/kissy-min.js,p/ ...