当前位置: 首页 > Web前端 > HTML5

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

时间:2023-04-05 20:58:07 HTML5

/***获取属于该屏幕的屏幕*@returns{string}xs为超小屏幕sm为小屏幕md为中屏幕lg为大屏幕*/export让getScreen=function(){if(win.matchMedia("(min-width:1200px)").matches){return'lg';}elseif(win.matchMedia("(min-width:992px)").matches){//screenand(min-width:992px)return'md'}elseif(win.matchMedia("(min-width:768px)").matches){//screenand(min-width:768px)return'sm'}else{return'xs'//超小屏}}address:链接地址