0%

禁止横竖屏切换、强制横竖屏


js判断屏幕横竖屏:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function orient() {
//alert('gete');
if (window.orientation == 0 || window.orientation == 180) {
$("body").attr("class", "portrait");
orientation = 'portrait';
return false;
}
else if (window.orientation == 90 || window.orientation == -90) {
$("body").attr("class", "landscape");
orientation = 'landscape';
return false;
}
}

$(function(){
orient();
});

$(window).bind( 'orientationchange', function(e){
orient();
});

ipad: 90 或 -90 横屏

ipad: 0180 竖屏

Andriod:0180 横屏

Andriod: 90 或 -90 竖屏

iphone 、ipad禁止横竖屏切换、强制横竖屏:

html5屏幕旋转事件 onorientationchange

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// 判断屏幕是否旋转

function orientationChange() {
switch(window.orientation) {
  case 0:
alert("肖像模式 0,screen-width: " + screen.width + "; screen-height:" + screen.height);
break;
  case -90:
alert("左旋 -90,screen-width: " + screen.width + "; screen-height:" + screen.height);
break;
  case 90:
alert("右旋 90,screen-width: " + screen.width + "; screen-height:" + screen.height);
break;
  case 180:
  alert("风景模式 180,screen-width: " + screen.width + "; screen-height:" + screen.height);
  break;
};
};

// 添加事件监听
addEventListener('load', function(){
orientationChange();
window.onorientationchange = orientationChange;
});
------ The End ------
您的认可是我不断进步的动力!