关于前端:js获取媒体查询屏幕的属于哪种屏幕

7次阅读

共计 358 个字符,预计需要花费 1 分钟才能阅读完成。

/**
 * 获取屏幕的属于哪种屏幕
 * @returns {string} xs 为超小屏  sm 为小屏  md 为中屏  lg 为大屏
 */

export let getScreen =  function () {if(win.matchMedia("(min-width: 1200px)").matches) {return 'lg';}else if(win.matchMedia("(min-width: 992px)").matches) {// screen and (min-width: 992px)
        return 'md'
    }else if(win.matchMedia("(min-width: 768px)").matches) {// screen and (min-width: 768px)
        return 'sm'
    }else {return 'xs' // 超小屏幕}
}

地址:链接地址

正文完
 0