方法一:在標簽上加入 onLoad="" onResize="" 方法 寫上對應的方法即可
方法二:window.onresize=function(){///.....} 在方法里面寫上對應的代碼即可
著兩種方法基本都可以解決問題。
<script>function adjust(obj){ var div = document.getElementById("pad"); var txt = document.getElementById("txt"); var w = document.body.clientWidth; var h = document.body.clientHeight; div.style.width = w/3; div.style.height = h/3; txt.style.width = w/6; txt.style.height = h/6;}window.onload=function(){ window.onresize = adjust; adjust();}</script><body style="margin:0px;height:0px;"><div id="pad" style="background:red;zoom:1;margin:0px;height:0px;"> <input type="text" id="txt"></div></body>
以上這篇jQuery監聽瀏覽器窗口大小的變化實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。
新聞熱點
疑難解答