In fact, it is mainly implemented through window.orientation. Let’s take a look at the code below
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
Statement: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