监听屏幕旋转事件window. 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;
    });

  

posted on 2016-11-16 16:48  半夏微澜ぺ  阅读(1787)  评论(0编辑  收藏  举报