Created
June 12, 2012 01:40
-
-
Save to/2913882 to your computer and use it in GitHub Desktop.
Window Size, Media Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0"> | |
</head> | |
<body> | |
<pre id="out"></pre> | |
</body> | |
<script> | |
function checkSizes(){ | |
var out = [ | |
'window.devicePixelRatio: ' + window.devicePixelRatio, | |
'window.innerWidth: ' + window.innerWidth, | |
'window.innerHeight: ' + window.innerHeight, | |
'window.screen.width: ' + window.screen.width, | |
'window.screen.height: ' + window.screen.height, | |
'', | |
]; | |
var tests = { | |
'-webkit-device-pixel-ratio' : window.devicePixelRatio, | |
'-moz-device-pixel-ratio' : window.devicePixelRatio, | |
'device-pixel-ratio' : window.devicePixelRatio, | |
'device-aspect-ratio' : window.screen.width + '/' + window.screen.height, | |
'aspect-ratio' : window.innerWidth + '/' + window.innerHeight, | |
'width' : window.innerWidth + 'px', | |
'device-width' : window.screen.width + 'px', | |
'height' : window.innerHeight + 'px', | |
'device-height' : window.screen.height + 'px', | |
} | |
for(var prop in tests){ | |
var test = prop + ': ' + tests[prop]; | |
if(window.matchMedia('(' + test + ')').matches) | |
out.push(test); | |
} | |
document.getElementById('out').textContent = out.join('\n'); | |
} | |
checkSizes(); | |
window.addEventListener('resize', checkSizes, true); | |
</script> | |
</html> |
Retinaの新iPadも昔のiPadはdevice-widthとdevice-heightが同じ。本当のデバイスピクセル数は、この値にデバイスピクセル比を乗算したものになる。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
resolutionのクエリ(dip)は、どこでもマッチしなかった。viewportにtarget-densitydpi=device-dpiを指定するとエラーになる。