zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

基于jQuery的判断iPad、iPhone、Android是横屏还是竖屏的代码

AndroidjQueryiphone代码 基于 判断 还是 ipad
2023-06-13 09:15:26 时间

其实主要是通过window.orientation实现,下面看下代码吧

复制代码代码如下:


functionorient(){
if(window.orientation==90||window.orientation==-90){
//ipad、iphone竖屏;Andriod横屏
$("body").attr("class","landscape");
orientation="landscape";
returnfalse;
}
elseif(window.orientation==0||window.orientation==180){
//ipad、iphone横屏;Andriod竖屏
$("body").attr("class","portrait");
orientation="portrait";
returnfalse;
}
}
//页面加载时调用
$(function(){
orient();
});
//用户变化屏幕方向时调用
$(window).bind("orientationchange",function(e){
orient();
});

屏幕方向对应的window.orientation值:

ipad:90或-90横屏
ipad:0或180竖屏
Andriod:0或180横屏
Andriod:90或-90竖屏