window.orientation:獲取屏幕旋轉的方向 window.addEventListener("resize", ()=>{ if (window.orientation === 180 || window.orientation === 0) { console.log('豎屏'); }; if (window.orientation === 90 || window.orientation === -90 ){ console.log('橫屏'); } });
@media screen and (orientation: portrait) { /*豎屏...*/ } @media screen and (orientation: landscape) { /*橫屏...*/ }