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