日常使用中经常需要获取页面的各种高度、宽度,本文分享了常见的获取高度和高度的属性获取方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <script language="javascript"> var str = ""; str = "\r\n可见区域宽:" document.body.clientwidth; str = "\r\n可见区域高:" document.body.clientheight; str = "\r\n可见区域宽:" document.body.offsetwidth " (包括边线和滚动条的宽)"; str = "\r\n可见区域高:" document.body.offsetheight " (包括边线的宽)"; str = "\r\n正文全文宽:" document.body.scrollwidth; str = "\r\n正文全文高:" document.body.scrollheight; str = "\r\n被卷去的高:" document.body.scrolltop; str = "\r\n被卷去的左:" document.body.scrollleft; str = "\r\n正文部分上:" window.screentop; str = "\r\n正文部分左:" window.screenleft; str = "\r\n屏幕分辨率的高:" window.screen.height; str = "\r\n屏幕分辨率的宽:" window.screen.width; str = "\r\n屏幕可用工作区高度:" window.screen.availheight; str = "\r\n屏幕可用工作区宽度:" window.screen.availwidth; str = "\r\n你的屏幕设置是 " window.screen.colordepth " 位彩色"; str = "\r\n你的屏幕设置 " window.screen.devicexdpi " 像素/英寸"; document.write(str); </script>
|