獲取屏幕的寬度和高度


  在js中,特別是在一些功能,比如底部返回哪些按鈕等,經常需要用到,這里綜合運用以下,以便可以以后快速獲取:

/**
 * 獲取屏幕的寬度和高度
 * @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
    }
}

  好了,至於怎么引入這個文件,想必大家都很熟悉了,這里就不一一介紹了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM