Last active
May 28, 2024 18:27
-
-
Save BroFox86/edff5c89e71333c721a2172937f85635 to your computer and use it in GitHub Desktop.
[Screen orientation] #responsive
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
if (screen && screen.orientation !== null) { | |
window.screen.orientation.onchange = () => { | |
switch (screen.orientation.type) { | |
case "landscape-primary": | |
console.log("That looks good."); | |
break; | |
case "landscape-secondary": | |
console.log("Mmmh… the screen is upside down!"); | |
break; | |
case "portrait-secondary": | |
case "portrait-primary": | |
console.log("Mmmh… you should rotate your device to landscape"); | |
break; | |
default: | |
console.log("The orientation API isn't supported in this browser :("); | |
} | |
}; | |
} | |
if (window.matchMedia("(orientation: portrait)").matches) { | |
// you're in PORTRAIT mode | |
} | |
if (window.matchMedia("(orientation: landscape)").matches) { | |
// you're in LANDSCAPE mode | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment