2013年1月19日星期六

【转】jQuery监听浏览器窗口大小的变化

方法一:在标签上加入  onLoad="" onResize=""  方法  写上对应的方法即可  方法二:window.onresize=function(){///.....} 在方法里面写上对应的代码即可  着两种方法基本都可以解决问题.  
  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>  

没有评论: