Safari Developer Library

Developer

DeviceMotionEvent Class Reference

Options
Deployment Target:

On This Page

DeviceMotionEvent

An instance of DeviceMotionEvent is created when significant change in motion occurs. The event object encapsulates the measurements of the interval, rotation rate, and acceleration of a device. More...

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


Not Applicable Not Applicable

Availability


Available in iOS 4.2 and later.
  • Initializes a new device motion event.

    Declaration

    JavaScript

    void initDeviceMotionEvent (in DOMString type, in boolean bubbles, in boolean cancelable, in Acceleration acceleration, in Acceleration accelerationIncludingGravity, in RotationRate rotationRate, in double interval);

    Parameters

    type

    The type of event. Pass devicemotion.

    bubbles

    Indicates whether this event is a bubbling event.

    cancelable

    Indicates whether this event can be canceled.

    acceleration

    The acceleration that the user is giving to the device. The Acceleration object has x, y, and z properties represented as doubles.

    accelerationIncludingGravity

    The total acceleration of the device, which includes the user acceleration and the gravity. The Acceleration object has x, y, and z properties represented as doubles.

    rotationRate

    The rotation rate of the device. The RotationRate object has alpha, beta, and gamma properties represented as doubles.

    interval

    The interval in milliseconds since the last time this event was fired.

    Availability

    Available in iOS 4.2 and later.

  • acceleration Property

    The acceleration that the user is giving to the device.

    Declaration

    JavaScript

    readonly attribute Acceleration acceleration

    Discussion

    The acceleration data are expressed in m/s^2 and use the following x, y, and z axis properties represented as doubles:

    x

    In the plane of the screen, positive towards the right side of the screen.

    y

    In the plane of the screen, positive towards the top of the screen.

    z

    Perpendicular to the screen, positive out of the screen.

    This property is null if the device cannot provide the user acceleration—that is, if the device does not have a gyroscope.

    Use the accelerationIncludingGravity property to get the total acceleration.

    Availability

    Available in iOS 4.2 and later.

  • The total acceleration of the device, which includes the user acceleration and the gravity.

    Declaration

    JavaScript

    readonly attribute Acceleration accelerationIncludingGravity

    Discussion

    The acceleration data is expressed in m/s^2 and use the x, y, and z axis properties described in acceleration. This property is never null because every Apple device has an accelerometer.

    Use the acceleration property to get the user acceleration only.

    Availability

    Available in iOS 4.2 and later.

  • interval Property

    The interval in milliseconds since the last device motion event.

    Declaration

    JavaScript

    readonly attribute double interval

    Availability

    Available in iOS 4.2 and later.

  • rotationRate Property

    The rotation rate of the device.

    Declaration

    JavaScript

    readonly attribute RotationRate rotationRate

    Discussion

    The RotationRate object specifies the device’s rate of rotation around three axes. It contains alpha, beta, and gamma properties represented as doubles as described in DeviceOrientationEvent Class Reference.

    This property is null if the device cannot provide the rate of rotation—that is, if the device does not have a gyroscope.

    Availability

    Available in iOS 4.2 and later.