您的位置:首页 > Web前端 > HTML5

html5监听屏幕旋转

2015-12-09 19:24 776 查看
屏幕旋转事件:onorientationchange

添加屏幕旋转事件侦听,可随时发现屏幕旋转状态(左旋、右旋还是没旋)。例子:

// 判断屏幕是否旋转

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;

};<br>};

// 添加事件监听

addEventListener('load', function(){

orientationChange();

window.onorientationchange = orientationChange;

});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: