javascript中获取dom元素高度和宽度
2017-12-29 15:09
381 查看
javascript中获取dom元素高度和宽度的方法如下:
网页可见区域宽: document.body.clientWidth
网页可见区域高: document.body.clientHeight
网页可见区域宽: document.body.offsetWidth (包括边线的宽)
网页可见区域高: document.body.offsetHeight (包括边线的高)
网页正文全文宽: document.body.scrollWidth
网页正文全文高: document.body.scrollHeight
网页被卷去的高: document.body.scrollTop
网页被卷去的左: document.body.scrollLeft
对应的dom元素的宽高有以下几个常用的:
元素的实际高度:document.getElementById("div").offsetHeight
元素的实际宽度:document.getElementById("div").offsetWidth
元素的实际距离左边界的距离:document.getElementById("div").offsetLeft
元素的实际距离上边界的距离:document.getElementById("div").offsetTop
window.getComputedStyle(document.getElementById("id")).height;
getComputedStyle:参考http://www.zhangxinxu.com/wordpress/2012/05/getcomputedstyle-js-getpropertyvalue-currentstyle/
网页可见区域宽: document.body.clientWidth
网页可见区域高: document.body.clientHeight
网页可见区域宽: document.body.offsetWidth (包括边线的宽)
网页可见区域高: document.body.offsetHeight (包括边线的高)
网页正文全文宽: document.body.scrollWidth
网页正文全文高: document.body.scrollHeight
网页被卷去的高: document.body.scrollTop
网页被卷去的左: document.body.scrollLeft
对应的dom元素的宽高有以下几个常用的:
元素的实际高度:document.getElementById("div").offsetHeight
元素的实际宽度:document.getElementById("div").offsetWidth
元素的实际距离左边界的距离:document.getElementById("div").offsetLeft
元素的实际距离上边界的距离:document.getElementById("div").offsetTop
window.getComputedStyle(document.getElementById("id")).height;
getComputedStyle:参考http://www.zhangxinxu.com/wordpress/2012/05/getcomputedstyle-js-getpropertyvalue-currentstyle/
相关文章推荐
- javascript中获取dom元素高度和宽度的方法如下:
- javascript中获取dom元素的高度和宽度
- 获取dom元素的宽度和高度
- 用javascript获取网页中各元素的高度和宽度等信息
- javascript获取隐藏元素(display:none)的高度和宽度的方法
- jQuery获取window、document、dom元素的高度和宽度函数分析
- JavaScript获取页面宽度高度大全 以及元素的位置
- javascript获取隐藏元素(display:none)的高度和宽度的方法
- javascript获取隐藏元素(display:none)的高度和宽度的方法(转)
- JavaScript、jQuery获取页面及个元素高度、宽度
- 获取dom元素的宽度和高度
- Javascript操作CSS之3——获取元素的真实高度和宽度
- JavaScript、JQuery获取网页的高度和宽度
- Javascript获取浏览器窗口大小 获取屏幕,浏览器,网页高度宽度
- js获取页面及个元素高度、宽度的代码
- javascript获取Dom节点元素
- JavaScript 准确获取手机屏幕的宽度和高度?
- javascript获取和判断浏览器窗口、屏幕、网页的高度、宽度等
- Javascript、Jquery获取浏览器和屏幕各种高度宽度
- Javascript、Jquery获取浏览器和屏幕各种高度宽度