Window: orientationchange イベント
Deprecated
Avoid using this feature in new projects. This feature may be a candidate for removal from web standards or browsers.>
orientationchange イベントは、端末の向きが変化した時に発生します。
このイベントはキャンセル不可で、バブリングもしません。
このイベントは非推奨です。代わりに、ScreenOrientation インターフェイスの change イベントを待ち受けしてください。
構文
このイベント名を addEventListener() などのメソッドで使用するか、イベントハンドラープロパティを設定するかしてください。
js
addEventListener("orientationchange", (event) => { })
onorientationchange = (event) => { }
イベント型
一般的な Event です。
例
orientationchange イベントは addEventListener メソッドで使用することができます。
js
window.addEventListener("orientationchange", (event) => {
console.log(
`端末の向きが ${event.target.screen.orientation.angle} になりました。`,
);
});
または、 onorientationchange イベントハンドラープロパティを使用します。
js
window.onorientationchange = (event) => {
console.log(
`端末の向きが ${event.target.screen.orientation.angle} になりました。`,
);
};
仕様書
| 仕様書 |
|---|
| Compatibility> # event-orientationchange> |