1. CSS判斷橫屏豎屏
寫在同一個CSS中
@media screen and (orientation: portrait) {
/*豎屏 css*/
}
@media screen and (orientation: landscape) and (min-width:450px){
/*橫屏 css*/
}
分開寫在2個CSS
豎屏
<link rel="stylesheet" media="all and (orientation:portrait)" href="portrait.css">
橫屏
<link rel="stylesheet" media="all and (orientation:landscape)" href="landscape.css">
2. JS判斷橫屏豎屏
var sEvent = "onorientationchange" in window ? "orientationchange" : "resize"; window.addEventListener(sEvent, function() {if (window.orientation === 180 || window.orientation === 0) { alert('豎屏狀態!');} if (window.orientation === 90 || window.orientation === -90 ){ alert('橫屏狀態!');} }, false);
?