[borwser window視窗大小 算是screen補充吧]主要因為移動IE遊覽器 寫了個相容

來源:互聯網
上載者:User

標籤:idt   ==   document   blog   代碼   div   行動裝置   cli   return   

先吧

來上代碼

 1     console.log(window.outerWidth + ‘--‘ + window.outerHeight);//唯讀整數,聲明了整個視窗的XY 2  3     var width  = window.innerWidth; 4     var height = window.innerHeight; 5     console.log("window.inner--" + width+ ‘--‘ + height); 6     console.log(‘-------------‘); 7     var width  = document.documentElement.clientWidth; 8     var height = document.documentElement.clientHeight; 9     console.log("document.documentElement.client--" + width + ‘--‘ + height);10     console.log(‘-------------‘);11     var width  = document.body.clientWidth;12     var height = document.body.clientHeight;13     console.log("document.body.client--" + width + ‘--‘ + height);14     console.log(‘-------------‘);15     console.log(document.compatMode);//相容模式是否開啟16                                      //開啟CSS1Compat 否backCompat

 

 

寫了個獲得行動裝置的windowXY JS高設3 P198-199

 1     //獲得window的大小,主要因為在行動裝置IE遊覽器上有區別 2     //移動IE遊覽器不支援inner client 3     //可以通過document.documentElement.client獲得 4     //compatMode判斷相容模式是否開啟 5     function windowClientXY(){ 6         var pageWidth  = window.innerWidth; 7         var pageHeight = window.innerHeight; 8         if(typeof pageWidth != ‘number‘){ 9             if(document.compatMode == ‘CSS1Compat‘){10                 pageWidth  = document.documentElement.clientWidth;11                 pageHeight = document.documentElement.clientHeight;12             }else{13                 pageWidth  = document.body.clientWidth;14                 pageHeight = document.body.clientHeight;15             }16         }17         return console.log("寬-" + pageWidth + ",高-" +pageHeight);18     }19     windowClientXY();20 21     //分別封裝22     function windowClientX(){23         var pageWidth  = window.innerWidth;24         if(typeof pageWidth != ‘number‘){25             if(document.compatMode == ‘CSS1Compat‘){26                 pageWidth  = document.documentElement.clientWidth;27             }else{28                 pageWidth  = document.body.clientWidth;29             }30         }31         return windowClientX = pageWidth32     }33     console.log(windowClientX());34 35     function windowClientY(){36         var pageHeight = window.innerHeight;37         if(typeof pageWidth != ‘number‘){38             if(document.compatMode == ‘CSS1Compat‘){39                 pageHeight = document.documentElement.clientHeight;40             }else{41                 pageHeight = document.body.clientHeight;42             }43         }44         return windowClientY = pageHeight45     }46     console.log(windowClientY());

 

[borwser window視窗大小 算是screen補充吧]主要因為移動IE遊覽器 寫了個相容

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.