js 检测屏幕分辨率


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;




refs



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM