Skip to content

Instantly share code, notes, and snippets.

@addisonhall
Last active January 16, 2017 11:28
Show Gist options
  • Save addisonhall/1ab5ef6d5126ca034916 to your computer and use it in GitHub Desktop.
Save addisonhall/1ab5ef6d5126ca034916 to your computer and use it in GitHub Desktop.
Get screen width, height, and orientation
// ----------------------------------------------
// Detect screen orientation
// ----------------------------------------------
var deviceOrientation = ''; // Declare globally to use throughout
function detectOrientation () {
var windowWidth = $(window).height();
var windowHeight = $(window).width();
if (windowWidth > windowHeight) {
deviceOrientation = 'landscape';
} else {
deviceOrientation = 'portrait';
}
}
window.addEventListener('resize', function () {
detectOrientation();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment