<!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>