浏览器高度和宽度js.txt
来自「取得浏览绝对大小的JS类」· 文本 代码 · 共 38 行
TXT
38 行
//取得浏览大小JS的类,兼容多种浏览器
//属性
//.width 宽度
//.height 高度
//.scrollWidth 带滚动条的宽度
//.scrollHeight 带滚动条的高度
//.scrollTop 内容高度
function browserInfo(){
if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight || document.documentElement.scrollTop)){
this.width = document.documentElement.clientWidth;
this.height = document.documentElement.clientHeight;
this.scrollTop = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
this.scrollWidth = document.documentElement.scrollWidth;
this.scrollHeight = document.documentElement.scrollHeight > document.documentElement.clientHeight ? document.documentElement.scrollHeight : document.documentElement.clientHeight;
} else if(document.body && (document.body.clientWidth || document.body.clientHeight || document.body.scrollTop)){
this.width = document.body.clientWidth;
this.height = document.body.clientHeight;
this.scrollTop = document.body.scrollTop;
this.scrollWidth = document.body.scrollWidth;
this.scrollHeight = document.body.scrollHeight > document.body.clientHeight ? document.body.scrollHeight : document.body.clientHeight;
} else {
this.width = 0;
this.height = 0;
this.scrollTop = 0;
this.scrollWidth = 0;
this.scrollHeight = 0;
}
if(typeof(window.innerWidth) == 'number' || typeof(window.innerHeight ) == 'number' ){
this.width = window.innerWidth > this.width ? window.innerWidth : this.width;
this.height = this.hieght ? this.height : window.innerHeight;
this.scrollWidth = window.innerWidth > this.scrollWidth ? window.innerWidth : this.scrollWidth;
this.scrollHeight = this.scrollHeight > window.innerHeight ? this.scrollHeight : window.innerHeight;
}
if(document.body && document.body.clientWidth){
this.scrollWidth = this.scrollWidth > document.body.scrollWidth ? this.scrollWidth : document.body.scrollWidth;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?