码迷,mamicode.com
首页 > 编程语言 > 详细

HTML5-javascript屏幕旋转事件:onorientationchange

时间:2015-12-26 20:56:50      阅读:485      评论:0      收藏:0      [点我收藏+]

标签:

/* 屏幕旋转事件: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;

    };

};

// 添加事件监听

addEventListener(‘load‘, function(){

    orientationChange();

    window.onorientationchange = orientationChange;

});

HTML5-javascript屏幕旋转事件:onorientationchange

标签:

原文地址:http://www.cnblogs.com/ns10086/p/5078778.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!