offsetLeft offsetTop offsetWidth offsetHeight

offsetLeft:元素的边框的外边缘距离与已定位的父容器(offsetparent)的左边距离(不包括元素的边框和父容器的边框)。

offsetTop:同理是指元素的边框的外边缘距离与已定位的父容器(offsetparent)的上边距离(不包括元素的边框和父容器的边框)。

offsetWidth:描述元素外尺寸宽度,是指元素内容宽度+内边距宽度(左右两个)+边框(左右两个),不包括外边距和滚动条部分。

offsetHeight:同理 描述元素外尺寸高度,是指 元素内容高度+内边距高度(上下两个)+边框(上下两个),不包括外边距和滚动条部分。

clientLeft clientTop clientWidth clientHeight

clientLeft:元素的内边距的外边缘和边框的外边缘的距离,实际就是边框的左边框宽度

clientTop:同理边框的上边框的宽度

clientWidth:用于描述元素内尺寸宽度,是指 元素内容+内边距 大小,不包括边框、外边距、滚动条部分

clientHeight:同理 用于描述元素内尺寸高度,是指 元素内容+内边距 大小,不包括边框、外边距、滚动条部分

scrollTop scrollLeft scrollWidth scrollHeight

scrollWidth:内容区域尺寸加上内边距加上溢出尺寸,当内容正好和内容区域匹配没有溢出时,这些属性与clientWidth和clientHeight相等 !important

scrollHeight:同上

scrollTop:滚动条上方卷去的高度

scrollLeft:滚动条左边卷去的宽度

下面贴上调试代码:

 <style>
*{margin:0;padding:0;}
#parent{ position: relative; padding: 10px; margin:30px; background-color:#CCC; border: solid 10px #fbc;}
#child{ height: 200px; width: 200px; padding: 10px; margin: 30px;border: solid 10px #fbc;background-color:#afb;}
#parent1{ padding: 10px; background-color: #fc8; width:300px; height:300px;overflow:auto ;clear:both; }
#child1 { background-color: #bfc; width: 400px; height: 400px;border: 10px solid #c8f;}
</style>
<body id="body"> <div id="parent">
<div id="child">
</div>
</div> <div id="parent1">
<div id="child1">
</div>
</div>
<script src="jquery_1.11.3.min.js"></script>
<script type="text/javascript"> var child = $("#child").get(0);
console.log($("#child"))//获得对象
console.log(child)//获得DOM元素
//$("#child")是一个对象 此处要获得DOM元素 因此要加get(0)
//get()是获取所有DOM元素的集合 因此加get(0) // console.log( "offsetParent: " + child.offsetParent.id);
// console.log( "offsetHeight: " + child.offsetHeight);
// console.log( "offsetWidth: " + child.offsetWidth);
// console.log( "offsetLeft: " + child.offsetLeft);
// console.log( "offsetTop: " + child.offsetTop); //---------------------------------------------------------------- // console.log( "clientHeight: " + child.clientHeight);
// console.log( "clientWidth: " + child.clientWidth);
// console.log( "clientLeft: " + child.clientLeft);
// console.log( "clientTop: " + child.clientTop); //---------------------------------------------------------------- var parent1 = $("#parent1").get(0);
// console.log( "clientHeight: " + parent1.clientHeight);
// console.log( "clientWidth: " + parent1.clientWidth);
console.log( "scrollHeight: " + parent1.scrollHeight);
console.log( "scrollWidth: " + parent1.scrollWidth);
//
// $("#parent1").scroll(function(){
// var scrollTop = document.documentElement.scrollTop||document.body.scrollTop
// var scrollLeft = document.documentElement.scrollLeft||document.body.scrollLeft
// console.log( "scrollTop: " + parent1.scrollTop);
// console.log( "scrollLeft: " + parent1.scrollLeft);
// }) </script>
</body>

注:此文为原创,如需转载请注明出处。

js和jq中常见的各种位置距离之offsetLeft/clientLeft/scrollLeft (一)的更多相关文章

  1. js和jq中常见的各种位置距离之offsetLeft和position().left的区别(四)

    offsetLeft:元素的边框的外边缘距离与已定位的父容器(offsetparent)的左边距离(不包括元素的边框和父容器的边框).position().left:使用position().left ...

  2. js和jq中常见的各种位置距离之offset和offset()的区别(三)

    offsetLeft:元素的边框的外边缘距离与已定位的父容器(offsetparent)的左边距离(不包括元素的边框和父容器的边框). offset().left:返回的是相对于当前文档的坐标,使用o ...

  3. js和jq中常见的各种位置距离之offset()和position()的区别(二)

    offset()返回的是相对于当前文档的坐标,position()返回的是相对于其定位的祖辈元素的坐标. 使用position()方法时事实上是把该元素当绝对定位来处理,获取的是该元素相当于最近的一个 ...

  4. HTML中常见的各种位置距离以及dom中的坐标讨论

    最近在学习JavaScript,特意买了一本犀牛角书来看看,尼玛一千多页,看的我头昏脑涨,翻到DOM这章节,突然记起平常在使用DOM时,碰到了好多的这个dom里面的各种宽度,高度,特意在此写一写,写的 ...

  5. Ajax 请求头中常见content-type

    四种常见的 POST 提交数据方式 HTTP 协议是以 ASCII 码传输,建立在 TCP/IP 协议之上的应用层规范.规范把 HTTP 请求分为三个部分:状态行.请求头.消息主体.协议规定 POST ...

  6. js中常见的问题

    js中常见的问题 原文链接 1.js获取select标签选中的值 原生js var obj = document.getElementByIdx_x(”testSelect”); //定位id var ...

  7. JS:JS中常见的 “函数名 is not a function” 错误

    js中常见的错误,例如Uncaught TypeError: x is not a function 其原因除了函数本身有错之外,还有一种很奇怪的情况:函数本身没有错,但是运行时就是不能正常运行.这种 ...

  8. JS中常见设计模式总结

    github: https://github.com/14glwu/FEInterviewBox/tree/master/JS%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F ...

  9. js从数组中删除指定值(不是指定位置)的元素

    RT: js从数组中删除指定值的元素,注意是指定值,而不是指定位置. 比如数组{1,2,3,4,5},我要删除其中的元素3,但是这个3的位置我是不知道的,只知道要删除值为3的这一个元素,请问要怎么写? ...

随机推荐

  1. hdu 6121 Build a tree

    /** * 题意:一棵 n 个点的完全 k 叉树,结点标号从 0 到 n - 1,求以每一棵子树的大小的异或和. * 解法:k叉树,当k=1时,特判,用xorn函数,具体解释:http://blog. ...

  2. listen 64

    Winning Athletes Engage in Arms Raise You see it when you watch almost any game: there's a touchdown ...

  3. storm源码剖析(3):topology启动过程

    storm的topology启动过程是执行strom jar topology1.jar MAINCLASS ARG1 ARG2 鉴于前面已经分析了脚本的解析过程,现在重点分析topology1.ja ...

  4. nginx 反向代理配置

    转载一篇特别好的nginx配置博文:http://www.cnblogs.com/hunttown/p/5759959.html

  5. CF 949D Curfew——贪心(思路!!!)

    题目:http://codeforces.com/contest/949/problem/D 有二分答案的思路. 如果二分了一个答案,首先可知越靠中间的应该大约越容易满足,因为方便把别的房间的人聚集过 ...

  6. 洛谷 1344 [USACO4.4]追查坏牛奶Pollutant Control——最大流

    题目:https://www.luogu.org/problemnew/show/P1344 那个边数的限制,只要把边权乘1001再+1即可.乘1001是因为有1000条边,这样流量小的不会因为边数多 ...

  7. 开源监控系统中 Zabbix 和 Nagios 哪个更好?

    监控平台的话,各有优劣,但基本都可以满足需求.等达到一定监控指标后,发现,最困难的是监控项目的管理. CMDB中小规模(服务器<=1k):Zabbix大规模(1k>=服务器<=10k ...

  8. Nuget-QRCode:jquery-qrcode

    ylbtech-Nuget-QRCode:jquery-qrcode 1.返回顶部 1. <!DOCTYPE html> <html> <head> <tit ...

  9. 面向对象(封装)get set的由来

    封装:是指隐藏对象的属性和实现细节,进对外提供公共访问方式 好处:将变化隔离.便于使用,提高重用性,提高安全性 封装原则:将不需要对外提供的额内容隐藏起来,把属性都隐藏,提供公共方法对其访问 pack ...

  10. tcp/ip协议和http协议

    TCP/IP 是一类协议系统,它是用于网络通信的一套协议集合. 传统上来说 TCP/IP 被认为是一个四层协议:应用层(telnet, ftp, http, smtp, dns等),传输层(tcp, ...