基于jQuery的代码来确定iPad、iPhone、Android是水平屏幕还是垂直屏幕。

事实上,它主要是通过window.orientation。让我们看看下面的代码

复制代码代码如下所示:
函数奥连特(){
如果(window.orientation = 90 | | window.orientation = = 90){
/ / iPad、iPhone手机横屏竖屏;
$(体),Attr(班
定位=景观;
返回false;
}
如果(window.orientation = = 0 | | { window.orientation = = 180)
/ / iPad、iPhone手机横屏竖屏;
$(体),Attr(班
定位= 'portrait;
返回false;
}
}
调用页加载
$(函数(){())
东方();
});
调用用户屏幕更改方向
$(窗口),Bind('orientationchange功能(e){ {)
东方();
});


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

90或90交叉屏
iPad:0或180垂直屏幕
手机:0或180横屏
手机:90或90竖屏