js获取媒体查询屏幕的属于哪种屏幕

Posted 老程

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js获取媒体查询屏幕的属于哪种屏幕相关的知识,希望对你有一定的参考价值。

/**
 * 获取屏幕的属于哪种屏幕
 * @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\' // 超小屏幕
    }
}
地址:链接地址

以上是关于js获取媒体查询屏幕的属于哪种屏幕的主要内容,如果未能解决你的问题,请参考以下文章