Skip to content

Instantly share code, notes, and snippets.

@thedaviddias
Created October 2, 2012 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedaviddias/3820265 to your computer and use it in GitHub Desktop.
Save thedaviddias/3820265 to your computer and use it in GitHub Desktop.
Iphone: orientation
<script>
if (!isNaN(window.orientation)) {
var orientation = (window.orientation == 0 || window.orientation == 180) ? "portrait" : "landscape";
$("body").addClass(orientation);
} else {
// Choose layout depending on viewport width
var orientation = ($(window).width() < 980) ? "portrait" : "landscape";
$("body").addClass(orientation);
}
</script>
OR
<script>
window.onorientationchange = function() {
var orientation = (window.orientation == 0 || window.orientation == 180) ? "portrait" : "landscape";
$("body").attr("class", orientation);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment