JavaScript的innerWidth与innerHeight
这两个属性是window对象的只读属性,声明了窗口的文档显示区的高度和宽度,以像素(px)为计量单位。 (注意:这里的宽度和高度不包括菜单栏、工具栏以及滚动条等的高度)
兼容写法:
function client() {
if (window.innerWidth != null) {
// ie9 + 最新浏览器
return {
width: window.innerWidth,
height: window.innerHeight
}
}
else if (document.compatMode === "CSS1compat") {
// 标准浏览器
return {
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight
}
}
else {
// 怪异浏览器
return {
width: document.body.clientWidth,
height: document.body.clientHeight
}
}
}