https://blog.csdn.net/qq_39083004/article/details/78498178

https://www.imooc.com/article/17571  推荐

offsetLeft

一个元素的offsetLeft值,就是这个元素左边框外,到自己的offsetParent对象的左边框内的距离

什么是offsetParent对象?

每一个元素,天生都有一个属性,叫做offsetParent,表示自己的“偏移参考盒子”,我们不称呼中文,就叫offsetParent。这个offsetParent是谁呢?

就是自己祖先元素中,离自己最近的已经定位的元素,如果自己的祖先元素中,没有任何盒子进行了定位,那么offsetParent对象就是body

op.offsetParent

无论这个盒子自己是否定位,自己的offsetParent就是按照上述方法寻找。

总结:

  IE6、7 IE8 IE9、IE9+、高级浏览器
offsetParent

如果自己没有定位,那么就是自己父亲中有width或者有height或者有定位的元素。

如果自己有定位,那么就是和高级浏览器一致。

和高级浏览器一致 自己祖先元素中,离自己最近的已经定位的元素
offsetLeft 和高级浏览器一致 多算一条border 自己的border外到offsetParet对象的border内

offsetWidth和offsetHeight

全线兼容,是自己的属性,和别的盒子无关。

一个盒子的offsetWidth值就是自己的 width+左右padding+左右border的宽度

如果盒子没有宽度,那么所有浏览器都将把px值当做offsetWidth,而不是100%;

如果盒子没有高度,用文字撑的,所有浏览器都将把px值当做offsetHeight

clientWidth和clientHeight

全线兼容,就一丢丢IE6的问题

client表示“客户端”这里就是一个名字而已,不用在意这个名字。

clientWidth就是自己的width+padding的值。 也就是说,比offsetWidth少了border。

如果盒子没有宽度,那么那么所有浏览器都将把px值当做clientWidth,而不是100%

如果盒子没有高度,用文字撑的,IE6 clientHeight是0,其他浏览器都是数值

卷动值scrollTop

页面的卷动值$(window).scrollTop();

窗口的高度$(window).height();

页面的总高度$(document).height();

页面的卷动值有一个范围:[0 , $(document).height() - $(window).height()];

也就是说,$(window).scrollTop() / ($(document).height() - $(window).height())一定是[0,1]。

clientHeight,offsetHeight,scrollHeight迷一样的三个值的更多相关文章

  1. clientHeight & offsetHeight & scrollHeight

    clientHeight & offsetHeight & scrollHeight scrollWidth/scrollHeight,offsetWidth/offsetHeight ...

  2. JavaScript获取浏览器高度和宽度值(documentElement,clientHeight,offsetHeight,scrollHeight,scrollTop,offsetParent,offsetY,innerHeight)

    IE中: document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> BODY对象高度 document.d ...

  3. 关于body/documentElement ---->clientHeight, offsetHeight, scrollHeight

    http://blog.csdn.net/woxueliuyun/article/details/8638427 http://blog.sina.com.cn/s/blog_9dd702d50101 ...

  4. clientHeight,offsetHeight与scrollHeight的相关知识

    在html里,width与height是最常用也是最基础的两个属性,因此,在js里,我们也经常需要操作这两个属性.js关于这两个属性提供了client*,offset*与scroll*,很多同学搞不清 ...

  5. 关于height、offsetheight、clientheight、scrollheight、innerheight、outerheight的区别

    二.也是平时经常用到的offsetheight 它返回的高度是内容高+padding+边框,但是注意哦,木有加margin哦,当然一般也木有啥需要把margin加进去的,以上代码为例,结果显示上图h2 ...

  6. 关于height、offsetheight、clientheight、scrollheight、innerheight、outerheight的区别一览

    平时,不管在pc端页面还是移动端页面,因为我们一般很少会设置某个块的的高度,但是呢,我有时候有需要取到这些高度以便于我们方便进行判断和下一步的编写.一般这个时候我都是直接的获取一个块的高度.heigh ...

  7. offsetHeight,scrollHeight,clientHeight,scrollTop以及pageX,clientX,offsetX,screenX,offsetLeft,style.left等的区别以及使用详解

    一.写在前面 在阅读本文前,希望大家能针对每个属性亲手测试,网上现有的大量相关博客都有不等的概念错误,毕竟亲手实践才能更好的掌握这些概念. 1.pageX,clientX,screenX与offset ...

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

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

  9. offsetHeight, clientHeight与scrollHeight的区别

      在网上搜了一下,结论非常笼统,讲IE从不讲版本,因此自己做了测试并上传结论.以下结论皆是在标准模式下测试通过的,没有测试quirk模式. clientHeight 大部分浏览器对 clientHe ...

随机推荐

  1. Codeforces Round #604 (Div. 2) E. Beautiful Mirrors

    链接: https://codeforces.com/contest/1265/problem/E 题意: Creatnx has n mirrors, numbered from 1 to n. E ...

  2. Linux 内存Cache和Buffer理解

    在 Linux 系统中,我们经常用 free 命令来查看系统内存的使用状态.在一个 RHEL6 的系统上,free 命令的显示内容大概是这样一个状态:   [root@tencent64 ~]# fr ...

  3. Go Node.js 生成的exe公布成windows服务

    环境变量 GOBIN E:\01_SOFT\go1.9.2\bin GOROOT E:\01_SOFT\go1.9.2 GOPATH(下载包的存放位置:go get github.com/gin-go ...

  4. win32线程栈溢出问题 (二)

    3.2.函数递归调用引发的栈溢出 写一段最简单的无穷递归代码,如下: #include "stdafx.h" void f(void) { f(); } int _tmain(in ...

  5. rc.local配置

    1.让系统默认启动的时候执行rc.local 启动我们想要启动进程:如:nginx ,memcached,或者是 php-fpm等! /usr/local/bin/redis-server /etc/ ...

  6. 2017.10.4 国庆清北 D4T1 财富

    (其实这题是luogu P1901 发射站 原题,而且数据范围还比luogu小) 题目描述 LYK有n个小伙伴.每个小伙伴有一个身高hi. 这个游戏是这样的,LYK生活的环境是以身高为美的环境,因此在 ...

  7. SSM 整合 ehcache 报错

    异常: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springfra ...

  8. if后的判断条件

    转自https://blog.csdn.net/lxn18392641463/article/details/78321080 先说明原因.这里不只是有代码规范的问题,还有汇编语言的问题,要知道为什么 ...

  9. php md5算法

    <!DOCTYPE html> <html> <body> <?php $str = "Shanghai"; echo md5($str) ...

  10. MySQL之级联删除、级联更新、级联置空

    1. 准备测试表 # 专业表major ))engine=innodb default charset=utf8; # 学生表mstudent ), major int)engine=innodb d ...