Screen.orientation
Experimental
これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。
orientation
は Screen
インターフェイスの読み取り専用プロパティで、現在の画面の向きを返します。
構文
var orientation = window.screen.orientation;
返値
画面の向きを表す ScreenOrientation
(en-US) のインスタンスです。
なお、古い接頭辞付きのものは DOMString
で ScreenOrientation.type
(en-US) と同等のものを返していました。
例
var orientation = screen.msOrientation || screen.mozOrientation || (screen.orientation || {}).type;
if (orientation === "landscape-primary") {
console.log("良い感じですね。");
} else if (orientation === "landscape-secondary") {
console.log("うーん…。画面が上下逆です!");
} else if (orientation === "portrait-secondary" || orientation === "portrait-primary") {
console.log("うーん…。スクリーンを横向きにした方がいいですよ");
} else if (orientation === undefined) {
console.log("このブラウザーは orientation API に対応していません :(");
}
仕様書
仕様書 | 状態 | 備考 |
---|---|---|
Screen Orientation API orientation の定義 |
草案 | 初回定義 |
ブラウザーの対応
BCD tables only load in the browser