Created
June 23, 2017 05:43
-
-
Save samthor/9449285425a9e26749d51c184852ef16 to your computer and use it in GitHub Desktop.
isLandscape function to determine whether device is landscape orientation
This file contains hidden or 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
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