Js 获取客户区大小

xiaoxiao2021-02-28  166

本文内容来自《JavaScript高级程序设计(第三版)》 内容, 只是方便大家以后可能会用到:

<script> function getViewport() { if(document.compatMode == "BackCompat"){ return { width:document.body.clientWidth, height:document.body.clientHeight }; }else { return { width:document.documentElement.clientWidth, height:document.documentElement.clientHeight }; } } var myDiv = document.getElementById("myDiv"); var view = getViewport(myDiv); alert( "宽度 " +view.width); alert("高度" +view.height); </script>

转载请注明原文地址: https://www.6miu.com/read-29190.html

最新回复(0)