There's a CSS file with these rules:
@media screen and (orientation:portrait) {
.foo {}
}
@media screen and (orientation:landscape) {
.foo {}
}
And then I've got this script, running on orientationchange
:
function checkOr(){
if (window.matchMedia("(orientation:portrait)").matches) {
console.log('portrait ' + window.orientation);
} else {
console.log('landscape '+ window.orientation);
}
}
But matchMedia always returns initial state of the page, when window.orientation returns correct value:
portrait -90
portrait 0
portrait -90
Tested on iPhone 5 and iPad 4 with latest iOS updates.
What am I doing wrong? Webkit bugtracker says that there must be rules for each media query, but that's not my case.