JavaScript方式检测横屏
window.orientation:获取屏幕旋转的方向
window.addEventListener("resize", ()=>{
if (window.orientation === 180 || window.orientation === 0) {
console.log('竖屏');
};
if (window.orientation === 90 || window.orientation === -90 ){
console.log('横屏');
}
});
CSS方式检测横屏
@media screen and (orientation: portrait) {
/*竖屏...*/
}
@media screen and (orientation: landscape) {
/*横屏...*/
}
来源:https://www.cnblogs.com/Model-Zachary/p/10888761.html