JQuery based iPad iPhone Android is landscape or portrait of the code


Window. orientation, so let’s look at the code

function orient() {
if (window.orientation == 90 || window.orientation == -90) {
//Portrait on ipad and iphone; Android landscape
$("body").attr("class", "landscape");
orientation = 'landscape';
return false;
}
else if (window.orientation == 0 || window.orientation == 180) {
//Ipad, iphone landscape; Android portrait
$("body").attr("class", "portrait");
orientation = 'portrait';
return false;
}
}
//Called when the page loads
$(function(){
orient();
});
//Called when the user changes screen direction
$(window).bind( 'orientationchange', function(e){
orient();
});

Window. orientation value corresponding to the screen orientation:

Ipad: 90 or -90 landscape Ipad: 0 or 180 portrait Android: 0 or 180 landscape Android: 90 or -90 portrait