Screen: orientation 屬性
Screen 介面的只讀屬性 orientation 返回螢幕的當前方向。
值
一個 ScreenOrientation 例項,表示螢幕的方向。
請注意,較舊的、帶有字首的版本返回一個字串,該字串等同於 ScreenOrientation.type。
示例
js
switch (screen.orientation.type) {
case "landscape-primary":
console.log("That looks good.");
break;
case "landscape-secondary":
console.log("Mmm… the screen is upside down!");
break;
case "portrait-secondary":
case "portrait-primary":
console.log("Mmm… you should rotate your device to landscape");
break;
default:
console.log("The orientation API isn't supported in this browser :(");
}
規範
| 規範 |
|---|
| 螢幕方向 # dom-screen-orientation |
瀏覽器相容性
載入中…