Skip to content

Instantly share code, notes, and snippets.

@clipperhouse
Created April 6, 2012 18:11
Show Gist options
  • Save clipperhouse/2321739 to your computer and use it in GitHub Desktop.
Save clipperhouse/2321739 to your computer and use it in GitHub Desktop.
Cross-platform mobile orientation change detection
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();
@clipperhouse
Copy link
Author

Has a small dependency on jQuery in the toggleClass method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment