Created
February 28, 2023 19:43
-
-
Save CezaryDanielNowak/f31190a7158fd5e3492c85d710ca67dc to your computer and use it in GitHub Desktop.
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
// gets device orientation. | |
// possible values: "landscape" | "portrait" | "" (can't detect) | |
const getCSSDeviceOrientation = () => { | |
function mediaQuery(orientation) { | |
return `(orientation: ${orientation})`; | |
} | |
const orientations = ['landscape', 'portrait']; | |
for (let orientation of orientations) { | |
if (window.matchMedia(mediaQuery(orientation)).matches) { | |
return orientation; | |
} | |
} | |
return ''; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment