判断横竖屏

@media (orientation: portrait) {   
    //竖屏  
}  
@media (orientation: landscape) {   
    //横屏  
}  

如:

@media screen and (orientation:landscape) {
    .cover {
        display: block;
    }
}
通过window.orientation来判断设备横竖屏

function checkOrient() {
        
    if (window.orientation == 0 || window.orientation == 180){
        var screenOrientation = 'portrait';
    // 竖屏 }
else if (window.orientation == 90 || window.orientation == -90){ var screenOrientation = 'landscape';
    // 横屏 }
return screenOrientation; } // 添加事件监听 addEventListener('load', function(){ checkOrient(); window.onorientationchange = checkOrient; });




原文地址:https://www.cnblogs.com/qianduanjingying/p/4992256.html