Home > Web Front-end > JS Tutorial > Code based on jQuery to determine whether iPad, iPhone, and Android are horizontal or vertical screen_jquery

Code based on jQuery to determine whether iPad, iPhone, and Android are horizontal or vertical screen_jquery

WBOY
Release: 2016-05-16 16:48:45
Original
1999 people have browsed it

In fact, it is mainly implemented through window.orientation. Let’s take a look at the code below

Copy code The code is as follows:

function orient() {
if (window. orientation == 90 || 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;
}
}
//Call
$(function(){
orient();
}) when the page is loaded;
//Call
$(window).bind when the user changes the screen orientation ('orientationchange', function(e){
orient();
});

The window.orientation value corresponding to the screen orientation:

ipad: 90 or -90 for landscape screen
ipad: 0 or 180 for portrait screen
Andriod: 0 or 180 for landscape screen
Andriod: 90 or -90 for portrait screen

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template