获取浏览器可视区域宽高

 1     /**
 2      * 获取浏览器可视区域宽度
 3      */
 4     function getViewPortOffset() {
 5         if (window.innerWidth) {
 6             return {
 7                 w: window.innerWidth,
 8                 h: window.innerHeight
 9             }
10         } else if (document.compatMode = "BackCompat") {
11             return {
12                 w: document.body.clientWidth,
13                 h: document.body.clientHeigth
14             }
15         } else {
16             return {
17                 w: document.documentElement.clientWidth,
18                 h: document.documentElement.clientHeight
19             }
20         }
21     }
22     console.log(getViewPortOffset());
23     

猜你喜欢

转载自www.cnblogs.com/lprosper/p/9404534.html