Skip to content

Instantly share code, notes, and snippets.

@CezaryDanielNowak
Created February 28, 2023 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CezaryDanielNowak/f31190a7158fd5e3492c85d710ca67dc to your computer and use it in GitHub Desktop.
Save CezaryDanielNowak/f31190a7158fd5e3492c85d710ca67dc to your computer and use it in GitHub Desktop.
// 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