点击JavaScript查看更多...
获取视口的尺寸
用法:handGetViewportOffset()
// 窗口初始化后调用,获取视口的w和h
const handGetViewportOffset = () => {
if (window.innerWidth) {
return {
w: window.innerWidth,
h: window.innerHeight
}
} else {
// ie8及其以下
if (document.compatMode === "BackCompat") {
// 怪异模式
return {
w: document.body.clientWidth,
h: document.body.clientHeight
}
} else {
// 标准模式
return {
w: document.documentElement.clientWidth,
h: document.documentElement.clientHeight
}
}
}
}
更多方法尽在专题JavaScript
网友评论