简体   繁体   English

Windows Mobile上的媒体查询检测

[英]Media Query detection on windows mobile

if (window.matchMedia("(min-width: 320px)").matches) {
    alert("width 320"); // works
}
if (window.matchMedia("(min-width: 768px)").matches) {
    alert("width 768");
}
if (window.matchMedia("(min-resolution: 2.4dppx)").matches) {
    alert("2.4dppx");
} 
if (window.matchMedia("(min-resolution: 217dpi)").matches) {
    dpi = 217;
} 
if (window.matchMedia("(min-resolution: 252dpi)").matches) {
    dpi = 252;
} 
if (window.matchMedia("(min-resolution: 331dpi)").matches) {
    dpi = 331;
} 
if (window.matchMedia("(min-resolution: 332dpi)").matches) {
    dpi = 332;
    }

I'm testing on Lumia 920 and only width 320 works, none other, I want to know the DPI. 我正在测试Lumia 920并且只有width 320工作,没有其他,我想知道DPI。 Tried everything, its just min-resolution that doesn't work. 尝试了一切,它只是最小分辨率,不起作用。

I think this is because you have only min-width defined. 我认为这是因为你只定义了min-width。 if you are searching for min-width:320px - this query is met always - even you have bigger resolution. 如果你正在寻找最小宽度:320px - 这个查询总是得到满足 - 即使你有更大的分辨率。 Try something like 尝试类似的东西

if (window.matchMedia("(min-width: 320px) and (max-width: 767)").matches) {
    alert("width 320"); // works
}//one px less then the query in next statement

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM