2013-05-01 59 views
3
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; 
    } 

我在Lumia 920上测试,只有width 320工作,其他,我想知道DPI。试了一下,它的最小分辨率不起作用。Windows Mobile上的媒体查询检测

+0

按【规范】(http://www.nokia.com/global/products/phone/lumia920/specifications/)您所有的疑问应该匹配。 – Pavlo 2013-05-01 17:19:20

+0

确切的,但他们不是。 :( – 3zzy 2013-05-01 17:24:00

回答

2

我认为这是因为你只有最小宽度的定义。 如果你正在寻找最小宽度:320px - 这个查询总是被满足 - 即使你有更大的分辨率。 试着这么做

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