2013-05-01 58 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