在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 } }
好了,至於怎么引入這個文件,想必大家都很熟悉了,這里就不一一介紹了。