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 DeviceMotionEvent
Target DefaultView (window)
Default Action None
Event handler property GlobalEventHandlers.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
};

Other properties

Property Type Description
alpha Read only double (float) The current orientation of the device around the Z axis; that is, how far the device is rotated around a line perpendicular to the device.
beta Read only double (float) The current orientation of the device around the X axis; that is, how far the device is tipped forward or backward.
gamma Read only double (float) The current orientation of the device around the Y axis; that is, how far the device is turned left or right.
absolute Read only boolean This value is true if the orientation is provided as a difference between the device coordinate frame and the Earth coordinate frame; if the device can't detect the Earth coordinate frame, this value is false.

Specifications

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

Browser compatibility

No compatibility data found. Please contribute data for "api.Window.deviceorientation_event" (depth: 1) to the MDN compatibility data repository.

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 7.0 (Yes) 3.6[1] ? ? ?
Feature Android Edge Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 3.0 (Yes) 3.6[1] No support 12 4.2

[1] Firefox 3.6, 4, and 5 supported mozOrientation versus the standard DeviceOrientation event.

See also

Document Tags and Contributors

Tags: 
Last updated by: estelle,