Skip to content

Instantly share code, notes, and snippets.

@BroFox86
Last active May 28, 2024 18:27
Show Gist options
  • Save BroFox86/edff5c89e71333c721a2172937f85635 to your computer and use it in GitHub Desktop.
Save BroFox86/edff5c89e71333c721a2172937f85635 to your computer and use it in GitHub Desktop.
[Screen orientation] #responsive
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