獲取屏幕的寬度和高度

  在js中,特別是在一些功能,好比底部返回哪些按鈕等,常常須要用到,這裏綜合運用如下,以即可以之後快速獲取:javascript

/**
 * 獲取屏幕的寬度和高度
 * @returns {*}
 */
function client() {
    if(window.innerWidth){ // ie9+ 最新的瀏覽器
        return {
            width: window.innerWidth,
            height: window.innerHeight
        }
    }else if(document.compatMode === "CSS1Compat"){ // W3C
        return {
            width: document.documentElement.clientWidth,
            height: document.documentElement.clientHeight
        }
    }

    return {
        width: document.body.clientWidth,
        height: document.body.clientHeight
    }
}

  好了,至於怎麼引入這個文件,想必你們都很熟悉了,這裏就不一一介紹了。java

相關文章
相關標籤/搜索