获取网页可见区域宽高(封装免邮)

//获取网页可见区域宽高
function getViewPortOffset() {
    if(window.innerWidth) {
        return {
            w: window.innerWidth,
            h: window.innerHeight
        }
    } else {
        if(document.compatMode === "BackCompat") {
            //compatMode 用来确认是否关闭或开启了标准兼容模式
            //BackCompat:标准兼容模式关闭。
            //CSS1Compat:标准兼容模式开启。
            return {
                w: document.body.clientWidth,
                h: document.body.clientHeight
            }
        } else {
            return {
                w: document.documentElement.clientWidth,
                y: document.documentElement.clientHeight
            }
        }
    }

}

  

posted @ 2018-10-10 12:08  false-  阅读(138)  评论(0)    收藏  举报