js自定义获取浏览器宽高

/**
* @description js自定义获取浏览器宽高
*
* IE8 和 IE8 以下的浏览器不兼容
* window.innerWidth
* window.innerHeight
*
* html 头文件部加 <!doctype html> 表示启用标准模式
* 标准模式 兼容所有浏览器
*
* document.body.clientWidth
* document.body.clientHeight
*
* document.documentElement.clientWidth
* document.documentElement.clientHeight
*
* @returns {width:0,height:0}
*/
function getViewPortOffset(){
if(window.innerWidth){
return {
width:window.innerWidth,
height:window.innerHeight
}
}else{
//混杂模式(兼容IE8以下)
if(document.compatMode == 'BackCompat'){
return{
width:document.body.clientWidth,
height:document.body.clientHeight
}
}else{
return {
width:document.documentElement.clientWidth,
height:document.documentElement.clientHeight
}
}
}
}

猜你喜欢

转载自www.cnblogs.com/M87-A/p/11166446.html
今日推荐