Created
April 6, 2012 18:11
-
-
Save clipperhouse/2321739 to your computer and use it in GitHub Desktop.
Cross-platform mobile orientation change detection
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
if (window.onorientationchange) { | |
window.onorientationchange = updateOrientation; | |
} else { | |
window.onresize = updateOrientation; | |
} | |
var body = $(document.body); | |
function updateOrientation() { | |
var islandscape = window.orientation != null ? window.orientation != 0 : window.innerWidth > window.innerHeight; | |
body.toggleClass("landscape", islandscape); | |
} | |
updateOrientation(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Has a small dependency on jQuery in the toggleClass method.