In fact, mainly through the Window.orientation implementation, the following look at the code
Copy Code code as follows:
Function Orient () {
if (window.orientation = = | | window.orientation = = 90) {
ipad, iphone vertical screen; andriod horizontal screen
$ ("Body"). attr ("Class", "Landscape");
Orientation = ' landscape ';
return false;
}
else if (window.orientation = 0 | | window.orientation = = 180) {
ipad, iphone horizontal screen; andriod vertical screen
$ ("Body"). attr ("Class", "Portrait");
Orientation = ' Portrait ';
return false;
}
}
Called when the page loads
$ (function () {
Orient ();
});
Called when the user changes the screen orientation
$ (window). bind (' Orientationchange ', function (e) {
Orient ();
});
Window.orientation Value for screen orientation:
Ipad:90 or-90 horizontal screen
ipad:0 or 180 vertical screen
andriod:0 or 180 horizontal screen
Andriod:90 or-90 vertical screen