判断手机旋转代码 屏幕旋转的事件和样式

屏幕旋转的事件和样式
事件
window.orientation,取值:正负90表示横屏模式、0和180表现为竖屏模式;
 
 
window.onorientationchange = function(){
    switch(window.orientation){
        case -90:
        case 90:
        alert("横屏:" + window.orientation);
        case 0:
        case 180:
        alert("竖屏:" + window.orientation);
        break;
    }
}  
 
 
 
样式
 
 
//竖屏时使用的样式
@media all and (orientation:portrait) {
.css{}
}
 
//横屏时使用的样式
@media all and (orientation:landscape) {
.css{}
}
原文地址:https://www.cnblogs.com/qhorse/p/4843503.html