在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
}
}
好了,至于怎么引入這個檔案,想必大家都很熟悉了,這里就不一一介紹了,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/156198.html
標籤:JavaScript
上一篇:用原生JS求和
下一篇:Ajax基礎原理與應用
