Created
May 5, 2013 18:34
-
-
Save garnu/5521705 to your computer and use it in GitHub Desktop.
Detect orientation change on iOS and Android + 180 degrees rotation fix for Android.
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
var orientation = (window.innerHeight > window.innerWidth)? "portrait" : "landscape"; | |
$(window).on("orientationchange resize", checkOrientation); | |
var checkOrientation = function() { | |
var newOrientation = (window.innerHeight > window.innerWidth)? "portrait" : "landscape"; | |
if(newOrientation == orientation) { return; } // no change | |
setInterval(checkOrientation, 1000); // recheck after 1 second for Android devices | |
orientation = newOrientation; | |
if(orientation == "portrait") { | |
// do something | |
} | |
else { // portrait | |
// do something else | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment