Provides a consistent API to the 3-axis accelerometer on all platforms.

A 1-axis accelerometer measures linear acceleration along a single axial direction. A 3-axis accelerometer is constructed by combining three orthogonal 1-axis accelerometers. In this way all 3D linear motions are captured, where ideally each accelerometer measures acceleration that is independent along each axis. For more information on coordinate frames, refer to the Coordinate Frames page.

The 3-axis accelerometer measurement consists of values: x, y, z. Each value corresponds to the axial linear acceleration of the device, measured in meters per second squared (m/s2).

When motion events are not available on the device, Accelerometer events are polyfilled with pan touch events.


var accelerometer = new MotionStack.Accelerometer();

accelerometer.start(function(e) {
  console.log(e.x, e.y, e.z);



new MotionStack.Accelerometer([options])

Create a new Accelerometer instance object.

Argument Type Description
options Object Options to pass in for the new Accelerometer instance (optional)

  • frame {String}
  • Reports the data relative to the specified coordinate system. Refer to the coordinates frame page for more details.

    • "device" Reference frame fixed to the device.
    • "world" Reference frame fixed to the Earths gravity.
    • "user" Reference frame fixed to the user. It is a combination of device-frame and world-frame and assumes the user is holding the device in portrait mode in-front of them.

    Default: "device"

  • fireOnAnimationFrame {Boolean}
  • Only emit the latest event within requestAnimationFrame intervals.

    Default: false

  • source {String}
  • The source used to calculate the reported data in order of approximation. If the specified source is not available, then the next available source is used.

    • "accelerometer" accelerometer sensor.
    • "touch" touch sensor.

    Default: "accelerometer"

var accelerometer = new MotionStack.Accelerometer({frame: "device"});

Static Methods


Returns a Boolean describing whether the device has an accelerometer.

MotionStack.Accelerometer.isSupported(); // true or false

Instance Methods

start(callback, [context])

Start receiving accelerometer updates.

Argument Type Description
callback Function Callback function that receives an object as an argument

  • function(e)
  • e.x, e.y, e.z {Number}
    Axial components of linear acceleration in the frame specified in the constructor (m/s2)
  • e.gravity.x, e.gravity.y, e.gravity.z {Number}
    Axial components of total acceleration including gravity in the frame specified in the constructor (m/s2)
  • e.polyfillAcceleration {Boolean}
    Specifies whether the gravity was extracted from the total acceleration with the help of the gyroscope
  • e.timeStamp {Number}
    The time in milliseconds when the data is collected.
  • e.interval {Number}
    The time in milliseconds between consecutive readings.
  • e.source {String}
    The source used to calculate the reported data.

    • "accelerometer" accelerometer sensor.
    • "touch" touch sensor.

context Object Context in which to invoke the callback (optional).
accelerometer.start(function(e) {
  console.log(e.x, e.y, e.z);


Stop accelerometer updates.