js和jq中常见的各种位置距离之offsetLeft/clientLeft/scrollLeft (一)
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 (一)的更多相关文章
- js和jq中常见的各种位置距离之offsetLeft和position().left的区别(四)
offsetLeft:元素的边框的外边缘距离与已定位的父容器(offsetparent)的左边距离(不包括元素的边框和父容器的边框).position().left:使用position().left ...
- js和jq中常见的各种位置距离之offset和offset()的区别(三)
offsetLeft:元素的边框的外边缘距离与已定位的父容器(offsetparent)的左边距离(不包括元素的边框和父容器的边框). offset().left:返回的是相对于当前文档的坐标,使用o ...
- js和jq中常见的各种位置距离之offset()和position()的区别(二)
offset()返回的是相对于当前文档的坐标,position()返回的是相对于其定位的祖辈元素的坐标. 使用position()方法时事实上是把该元素当绝对定位来处理,获取的是该元素相当于最近的一个 ...
- HTML中常见的各种位置距离以及dom中的坐标讨论
最近在学习JavaScript,特意买了一本犀牛角书来看看,尼玛一千多页,看的我头昏脑涨,翻到DOM这章节,突然记起平常在使用DOM时,碰到了好多的这个dom里面的各种宽度,高度,特意在此写一写,写的 ...
- Ajax 请求头中常见content-type
四种常见的 POST 提交数据方式 HTTP 协议是以 ASCII 码传输,建立在 TCP/IP 协议之上的应用层规范.规范把 HTTP 请求分为三个部分:状态行.请求头.消息主体.协议规定 POST ...
- js中常见的问题
js中常见的问题 原文链接 1.js获取select标签选中的值 原生js var obj = document.getElementByIdx_x(”testSelect”); //定位id var ...
- JS:JS中常见的 “函数名 is not a function” 错误
js中常见的错误,例如Uncaught TypeError: x is not a function 其原因除了函数本身有错之外,还有一种很奇怪的情况:函数本身没有错,但是运行时就是不能正常运行.这种 ...
- JS中常见设计模式总结
github: https://github.com/14glwu/FEInterviewBox/tree/master/JS%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F ...
- js从数组中删除指定值(不是指定位置)的元素
RT: js从数组中删除指定值的元素,注意是指定值,而不是指定位置. 比如数组{1,2,3,4,5},我要删除其中的元素3,但是这个3的位置我是不知道的,只知道要删除值为3的这一个元素,请问要怎么写? ...
随机推荐
- listen 72
Warmer Temps May Bollux Botanicals Global warming might seem like a botanical boon. After all, milde ...
- HihoCoder1649 : 漏写的数字([Offer收割]编程练习赛38)(模拟题)
描述 小A今年刚上幼儿园,正在学习写100以内的数字.幼儿园的老师留了一项作业,要求小A从某个100以内的数X开始一直写到另一个100以内的数Y(Y - X > 1). 不过粗心的小A在作业中漏 ...
- AtCoder Grand Contest #026 C - String Coloring
Time Limit: 3 sec / Memory Limit: 1024 MB Score : 600600 points Problem Statement You are given a st ...
- MYSQL_与excel结合在excel中用&连接符快速创建表头_20161125
excel &连接符快速创建表头 复制c列内容 CREATE TABLE A0001restaurant ( #用户明细表 城市 ), 区块 ), 用户ID ), 用户名称 ), 用户地址 ) ...
- poj1094Sorting It All Out——拓扑排序
题目:http://poj.org/problem?id=1094 看到此题,首先觉得这是一种层层递进的关系,所以可以想到用拓扑排序: 就像人工排序,每次需要找到一个最小的,再找到新的最小的……所以用 ...
- vmware 虚拟网卡配置
VMware虚拟机进阶:[1]网卡配置 1. 可以在下面这个图中看到几种网络设置模式,一直以来我们都喜欢用桥接模式和NAT模式,因为这两种模式是最符合一般人上网设置的模式,下面我们就一种种介绍个大家 ...
- USB相关资料
http://www.usb.org/developers/defined_class/#BaseClass00h http://blog.csdn.net/lizzywu/article/detai ...
- Linux下使用doxygen+vim生成c语言源程序文档的方法
1.安装 doxygen 有两种获得 doxygen 的方法.可以下载预编译的可执行文件,也可以从 SVN 存储库下载源代码并自己编译.清单 1 演示的是后一种方法. 清单 1. 安装和构建 doxy ...
- 干货:SEO长尾关键词优化方法和技巧
在网站SEO优化上,优化比较成功的网站,根据SEO界前辈的经验结论,网站的总流量主要来源于长尾关键词,占网站总流量的80%.长尾关键词主要分布在网站的文章页,其次就是栏目页title.标签页.专题页等 ...
- zookeeper原理与实践(一)----zookeeper的基本功能
我们现在围绕两个问题来学习zookeeper: 什么是zookeeper? zookeeper基础知识 什么是zookeeper: zookeeper是hadoop下面的一个子项目,是一个分布式协调服 ...