mozilla
Your Search Results

    DeviceOrientationEvent

    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.

    General info

    Specification
    Orientation
    Interface
    DeviceOrientationEvent
    Bubbles
    No
    Cancelable
    No
    Target
    DefaultView (window)
    Default Action
    None

    Properties

    Property Type Description
    target Read only EventTarget The event target (the topmost target in the DOM tree).
    type Read only DOMString The type of event.
    bubbles Read only boolean Does the event normally bubble?
    cancelable Read only boolean Is it possible to cancel the event?
    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.

    Example

    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 );
        }, false);
    }
    
    var handleOrientationEvent = function( frontToBack, leftToRight, rotateDegrees ){
        //do something amazing
    };
    

    Browser Compatibility

    Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
    Basic support

    7.0

    3.6

    ? ? ?
    Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
    Basic support

    3.0

    3.6

    NotĀ supported 12

    4.2

    Firefox 3.6, 4, and 5 supported mozOrientation versus the standard DeviceOrientation event

    See also

    Document Tags and Contributors

    Contributors to this page: Sheppy, cgack, louisremi
    Last updated by: louisremi,