js 检测屏幕分辨率
class screenChecker {
constructor() {
this.screen = window.screen;
this.fullscreen = false;
this.screenSize = {
width: 0,
height: 0,
};
this.init();
}
getScreenSize() {
const {
height,
width,
} = this.screen;
return {
width,
height,
};
}
isFullScreen() {
// 全屏判断逻辑,可用的屏幕大小等于实际的屏幕大小, 浏览器地址栏高度为 0
// availLeft, availTop, ???? 不推荐使用
const {
availHeight,
availWidth,
height,
width,
} = this.screen;
this.fullscreen = (availHeight === height && availWidth === width);
return this.fullscreen;
}
getDepth() {
const {
colorDepth,
pixelDepth,
} = this.screen;
return {
colorDepth,
pixelDepth,
};
}
isScreenResized() {
// TODO: 屏幕缩放检测
return false;
}
getOrientation() {
// 屏幕方向,判断屏幕是否旋转
const {
orientation: {
angle,
type,
// onchange,
},
} = this.screen;
return {
angle,
type,
};
}
init() {
this.getScreenSize();
this.isFullScreen();
}
}
export default screenChecker;