Re: [問題] javascript 取得瀏覽器長寬的問題

看板Ajax作者 (愚人)時間17年前 (2007/10/09 10:57), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串4/4 (看更多)
※ 引述《kewl (痴)》之銘言: : 取得瀏覽器長跟寬我知道可以用下面的用法 : var w = windows.document.body.clientWidth // 取得 width : var h = windows.document.body.clientHeight // 取得 height : 那請問有沒有辦法在瀏覽器的大小改變的同時改變 w 跟 h 的值阿 : 或是請問 javascript 有辦法取得 "改變視窗大小" 這個事件嗎 : 多謝指點囉 :) 關於長寬的東西,可以參考別人的 code :P http://interface.eyecon.ro 這是 jQuery 的 interface plugin =================================================================== iutil.js getClient : function(e) { var h, w, de; if (e) { w = e.clientWidth; h = e.clientHeight; } else { de = document.documentElement; w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth; h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight; } return {w:w,h:h}; ============================================================================ getSize : function(e) { var w = jQuery.css(e,'width'); var h = jQuery.css(e,'height'); var wb = 0; var hb = 0; var es = e.style; if (jQuery(e).css('display') != 'none') { wb = e.offsetWidth; hb = e.offsetHeight; } else { oldVisibility = es.visibility; oldPosition = es.position; es.visibility = 'hidden'; es.display = 'block'; es.position = 'absolute'; wb = e.offsetWidth; hb = e.offsetHeight; es.display = 'none'; es.position = oldPosition; es.visibility = oldVisibility; } return {w:w, h:h, wb:wb, hb:hb}; }, ========================================================================== 把這些片段獨立出來用也是不錯的方法, <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "" rel="nofollow">http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script language="javascript"> function getClient(e) { var h, w, de; if (e) { w = e.clientWidth; h = e.clientHeight; } else { de = document.documentElement; w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth; h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight; } // test it. // alert(h+":"+w); return {w:w,h:h}; } </script> </head> <body> <a href="#" onclick="getClient(this.window);return false;">link</a> </body> </html> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.128.219.202

10/09 20:08, , 1F
下面獨立出來那個不錯 多謝:)
10/09 20:08, 1F
文章代碼(AID): #172kufgs (Ajax)
文章代碼(AID): #172kufgs (Ajax)