Web/API/Window/deviceorientation event

From Get docs


The deviceorientation event is fired when fresh data is available from an orientation sensor about the current orientation of the device as compared to the Earth coordinate frame. This data is gathered from a magnetometer inside the device. See Orientation and motion data explained for details.

Bubbles No
Cancelable No
Interface DeviceOrientationEvent
Event handler property window.ondeviceorientation

Examples

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
};

Specifications

Specification Status
DeviceOrientation Event SpecificationThe definition of 'DeviceOrientation event' in that specification. Editor's Draft

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
deviceorientation event Chrome

Full support 7

Edge

Full support ≤18

Firefox Full support 6


Full support 6


No support 3.6 — 6

Alternate Name'

Alternate Name' Uses the non-standard name: mozOrientation

IE

?

Opera

Full support 12

Safari

Full support Yes

WebView Android

Full support 3

Chrome Android

Full support 18

Firefox Android Full support 6


Full support 6


No support 4 — 6

Alternate Name'

Alternate Name' Uses the non-standard name: mozOrientation

Opera Android

Full support 12

Safari iOS

Full support 4.2

Samsung Internet Android

Full support 1.0

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
Uses a non-standard name.'
Uses a non-standard name.


See also