Skip to content

Instantly share code, notes, and snippets.

@gcoop
Created September 13, 2010 13:52
Show Gist options
  • Save gcoop/577306 to your computer and use it in GitHub Desktop.
Save gcoop/577306 to your computer and use it in GitHub Desktop.
var current_orientation; // Cache orientation.
x$('body').orientationchange(function() {
var newOrientation;
switch (window.orientation) // Switch out the windows orientation
{
case 0:
case 180: // Upside down.
newOrientation = 'portrait';
break;
case -90:
case 90:
newOrientation = 'landscape';
break;
}
if (current_orientation != newOrientation) // Ensure the new orientation isn't the same as the current.
{
x$('body').addClass(newOrientation);
x$('body').removeClass(current_orientation);
orientation_str = newOrientation; // Cache current orientation for comparison,
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment