用jQuery监听浏览器窗口的变化
1 $(window).resize(function () { //当浏览器大小变化时 2 alert($(window).height()); //浏览器时下窗口可视区域高度 3 alert($(document).height()); //浏览器时下窗口文档的高度 4 alert($(document.body).height()); //浏览器时下窗口文档body的高度 5 alert($(document.body).outerHeight(true)); //浏览器时下窗口文档body的总高度 包括border padding margin 6 });
1 <script> 2 function adjust(obj){ 3 var div = document.getElementById("pad"); 4 var txt = document.getElementById("txt"); 5 var w = document.body.clientWidth; 6 var h = document.body.clientHeight; 7 div.style.width = w/3; 8 div.style.height = h/3; 9 txt.style.width = w/6; 10 txt.style.height = h/6; 11 } 12 window.onload=function(){ 13 window.onresize = adjust; 14 adjust(); 15 } 16 </script> 17 <body style="margin:0px;height:0px;"> 18 <div id="pad" style="background:red;zoom:1;margin:0px;height:0px;"> 19 <input type="text" id="txt"> 20 </div> 21 </body>