Javascript——尺寸和定位(操作指南)__Java

來源:互聯網
上載者:User
<!DOCTYPE html><html><head><meta charset="GB2312"><title></title><style type="text/css">*{margin: 0px;padding: 0px;}</style><script type="text/javascript">/** * DOM元素尺寸大小與位置總結 * 1offsetWidth,offsetHeight: 用於描述元素外尺寸。指元素內容+內邊距+邊框,不包括外邊距和捲軸部分 *  * 2clientWidth,clientHeight:用於描述元素內尺寸。是指元素內容+內邊距大小,不包括邊框、外邊框、捲軸部分。 *  * 3clientTop,clientLeft:返回邊框尺寸大小。 *  * 4offsetTop,offsetLeft:返回該元素的左上方(邊框外邊緣)與已定位的父容器的邊框外邊緣距離尺寸大小 *  * 5document.body.scrollTop:網頁被捲去的高 *  * 6document.body.scrollLeft:網頁被捲去的寬 *  * 7 document.body.clientWidth:頁面可見地區的寬 *  * 8document.body.offsetWidth:頁面可見地區的寬(包含邊線的寬) *  * 9window.screen.height:螢幕辨別率的高 *  * 10window.screen.width:螢幕辨別率的寬 *  * *  *  *  *  */window.onload=function(){var divParent=document.getElementById('divParent');var divDisplay=document.getElementById('divDisplay');var scrollTop=document.getElementById('scrollTop');var windowProperties=document.getElementById('windowProperties');var webpage=document.getElementById('webpage');divParent.onscroll=function(){//scrollTop.innerText=divDisplay.scrollHeight+'px'+"==="+divDisplay.scrollHeight+"  "+divParent.scrollTop+" "+divParent.scrollLeft;//alert(1);//windowProperties.innerText='window.screen.height:'+window.screen.height+'window.screen.width:'+window.screen.width+'window.screen.availHeight:'+window.screen.availHeight;webpage.innerText='document.body.clientWidth: '+document.body.clientWidth+'document.body.clientHeight: '+document.body.clientHeight+'document.body.offsetWidth: '+document.body.offsetWidth+'document.body.offsetHeight: '+document.body.offsetHeight;}; };</script></head><body><div id="divParent" style="background-color: #aaa;padding:8px;border: solid 7px #000;height: 200px; width: 500px; overflow: auto;"><div id="divDisplay" style="background-color: #0f0;margin: 30px;padding: 10px;height: 400px; width: 200px; border: solid 3px #f00;"></div></div><div id="scrollTop"></div><div id="windowProperties"></div><div id="webpage"></div><script type="text/javascript">(function(){ var divDisplay=document.getElementById('divDisplay');document.writeln('offsetWidth: '+divDisplay.offsetWidth+'<br />');document.writeln('offsetHeight: '+divDisplay.offsetHeight+'<br />');document.writeln('clientWidth: '+divDisplay.clientWidth+'<br />');document.writeln('clientHeight: '+divDisplay.clientHeight+'<br />');document.writeln('clientTop: '+divDisplay.clientTop+'<br />');document.writeln('clientLef: '+divDisplay.clientLeft+'<br />');document.writeln('offsetTop: '+divDisplay.offsetTop);})();</script></body></html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.