jquery 如何获得窗口的宽和高

jquery 如何获得窗口的宽和高


慕斯王
浏览 521回答 1
1回答

慕尼黑8549860

提供你一个函数,获取浏览器显示部分的高度,兼容所有主流浏览器<script>function getWindowSize() {var client = {x:0,y:0};if(typeof document.compatMode != 'undefined' && document.compatMode == 'CSS1Compat') {client.x = document.documentElement.clientWidth;client.y = document.documentElement.clientHeight;} else if(typeof document.body != 'undefined' && (document.body.scrollLeft || document.body.scrollTop)) {client.x = document.body.clientWidth;client.y = document.body.clientHeight;}return client;}function getsize(){var size = getWindowSize();document.getElementById("width").value = size.x;document.getElementById("height").value = size.y;}</script><body onresize="getsize()">width:<input type="text" id="width" /><br />height:<input type="text" id="height" /></body>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JQuery