detect landscape orientation javascript code example
Example 1: screen rotation in css
@media screen and (orientation:portrait) { … }
@media screen and (orientation:landscape) { … }
Example 2: how to get orientation in js
if (window.matchMedia("(orientation: portrait)").matches) {
// you're in PORTRAIT mode
}
if (window.matchMedia("(orientation: landscape)").matches) {
// you're in LANDSCAPE mode
}