用JavaScript判断横屏竖屏问题

判断手机横竖屏状态:

 1 //判断手机横竖屏状态:
 2 
 3 function hengshuping() {
 4     if(window.orientation == 180 || window.orientation==0){
 5 alert("竖屏状态!");}
 6 }
 7     if(window.orientation == 90 || window.orientation == -90){
 8     alert("横屏状态!")
 9 }
10 window.addEventListener("onorientationchange"  in window  ? "orientationchange" : "resize",hengshuping,false);
11 
12 
13 
14 //移动端的浏览器一半都支持window.orientation 这个参数可以判断出手机是处在横竖屏的状态。
15 //从而根据实际需求而执行行营的程序。通过添加监听事件onorientationchange,进行执行就可以了。

 

posted @ 2016-03-31 17:22  小小僵尸  阅读(221)  评论(0编辑  收藏  举报