美文网首页
JavaScript琐碎知识

JavaScript琐碎知识

作者: 勇敢的心1025 | 来源:发表于2017-12-05 13:58 被阅读0次

1、获取页面中元素距离屏幕四周的距离

var div=document.getElementById("box");

var distance=div.getBoundingClientRect();

1、屏幕距离的问题

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

相关文章

网友评论

      本文标题:JavaScript琐碎知识

      本文链接:https://www.haomeiwen.com/subject/gsxcixtx.html