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
更多专业前端知识,请上 【猿2048】www.mk2048.com