Window: deviceorientation イベント

deviceorientation イベントは、端末の現在の向きを地球座標フレームと比較した場合に、方角センサーから最新のデータが得られた場合に発生します。このデータは端末内部の磁力計から収集されます。詳細については、向きと動きのデータの説明を参照してください。

バブリング いいえ
キャンセル 不可
インターフェイス DeviceOrientationEvent (en-US)
イベントハンドラープロパティ window.ondeviceorientation (en-US)

if (window.DeviceOrientationEvent) {
    window.addEventListener("deviceorientation", function(event) {
        // alpha: rotation around z-axis
        var rotateDegrees = event.alpha;
        // gamma: left to right
        var leftToRight = event.gamma;
        // beta: front back motion
        var frontToBack = event.beta;

        handleOrientationEvent(frontToBack, leftToRight, rotateDegrees);
    }, true);
}

var handleOrientationEvent = function(frontToBack, leftToRight, rotateDegrees) {
    // do something amazing
};

仕様書

Specification
DeviceOrientation Event Specification
# deviceorientation
DeviceOrientation Event Specification
# ref-for-dom-window-ondeviceorientation

ブラウザーの互換性

BCD tables only load in the browser

関連情報