html中元素尺寸、坐标的获取
来源:互联网 发布:node.exe是什么东西 编辑:程序博客网 时间:2024/05/16 17:29
html
<img src="src/images/bg5.jpg" alt=""><div class="main"> <div id='p' style="height:100px">asdasd</div></div>css
*{margin:0;padding:0;} .main{ width: 350px; height: 200px; background: green; position: relative; } #p{ width: 200px; height: 100px; border: 2px solid red; margin: 15px; padding: 20px; position: absolute; top: 35px; left: 30px; }
获取height(这里就不介绍width了)
//dom方法 var p=document.getElementById("p");
var str_dom="scrollHeight: "+p.scrollHeight;//140, 包含padding str_dom+=", offsetHeight: "+p.offsetHeight;//144, 包含padding和border str_dom+=", clientHeight: "+p.clientHeight;//140, 包含padding str_dom+=", height: "+p.style.height;//100px, 带单位,只有内嵌样式才能获取 /*str_dom+=", scrollWidth: "+p.scrollWidth; str_dom+=", offsetWidth: "+p.offsetWidth; str_dom+=", clientWidth: "+p.clientWidth;*/ console.log(str_dom); //jquery方法 var str_jq="height: "+$(p).height();//100.36364,补白 str_jq+=", innerHeight: "+$(p).innerHeight();//140.36364, 补白+padding str_jq+=", outerHeight: "+$(p).outerHeight();//144, 包括padding和border console.log(str_jq)//document var str_doc="doc.scrollHeight: "+document.body.scrollHeight; str_doc+=", doc.offsetHeight: "+document.body.offsetHeight; str_doc+=", doc.clientHeight: "+document.body.clientHeight; console.log(str_doc);//三个等高//window var str_win="win.height: "+window.screen.height;//包括工具栏高度 str_win+=", win.availHeight: "+window.screen.availHeight;//浏览器实际可用尺寸 console.log(str_win);获取y坐标
//坐标 var str_y="scrollTop: "+p.scrollTop;//0 str_y+=", offsetTop: "+p.offsetTop;//30, margin+top str_y+=", clientTop: "+p.clientTop;//2, border str_y+=", offsetY: "+event.offsetY;//相对于容器的y str_y+=", clientY: "+event.clientY;//相对于document的y console.log(str_y)
//jquery var str_y_jq="scrollTop: "+$(p).scrollTop();//0 str_y_jq+=", positionTop: "+$(p).position().top;//35, 相对于父容器的y坐标 str_y_jq+=", offsetTop: "+$(p).offset().top;//相对于document的绝对y坐标 console.log(str_y_jq)
阅读全文
0 0
- html中元素尺寸、坐标的获取
- 获取html元素的坐标
- html获取元素的坐标
- 获取html上元素的真正坐标
- jQuery获取HTML元素的坐标
- 浏览器中元素尺寸和坐标的名词解释
- jquery中获得元素尺寸和坐标的方法
- js获取table中td的绝对坐标(HTML元素定位)
- html元素位置,获取对象的绝对坐标
- javascript(获取或设置html元素的宽,高,坐标)
- 访问元素的尺寸和坐标
- UiAutomator中获取元素坐标
- 获取隐藏元素的尺寸
- 获取隐藏元素的尺寸
- 关于Js中获取元素的尺寸和位置
- JS中获取元素的尺寸及位置
- 计算html元素的坐标
- 获取元素的绝对坐标
- 日语词汇辨析:以来と以降と以後
- 《Visual Basic 程序设计》——>过程
- 隐马尔科夫模型(HMM)
- ASP.NET Razor – VB 循环和数组
- System.ServiceModel.AddressAccessDeniedException
- html中元素尺寸、坐标的获取
- response得输出
- spark-cluster及yarn-client说明
- Angularjs启动过程
- Oracle对于表中字段的相关操作
- 《Visual Basic 程序设计》——>文件
- java 正则表达式
- 编译器的字节范围测试
- 自己编译 LAMP Centos 7.2+Apache2.4+ Mysqlnd 5.6+PHP 7 详解