Skip to content

Instantly share code, notes, and snippets.

@samthor
Created June 23, 2017 05:43
Show Gist options
  • Save samthor/9449285425a9e26749d51c184852ef16 to your computer and use it in GitHub Desktop.
Save samthor/9449285425a9e26749d51c184852ef16 to your computer and use it in GitHub Desktop.
isLandscape function to determine whether device is landscape orientation
function isLandscape() {
var object = window.screen.orientation || window.screen.msOrientation || window.screen.mozOrientation || null;
if (object) {
if (object.type.indexOf('landscape') !== -1) { return true; }
if (object.type.indexOf('portrait') !== -1) { return false; }
}
if ('orientation' in window) {
var value = window.orientation;
if (value === 0 || value === 180) {
return false;
} else if (value === 90 || value === 270) {
return true;
}
}
// fallback to comparing width to height
return window.innerWidth > window.innerHeight;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment