监听屏幕旋转的事件:onorientationchange
eg:
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})
横屏样式
@media all and (orientation:landscape) {.css{}}
竖屏样式
@media all and (orientation:portrait) {.css{}}
