Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. Accelerometer

Accelerometer

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.

TheAccelerometer interface of theSensor APIs provides on each reading the acceleration applied to the device along all three axes.

To use this sensor, the user must grant permission to the'accelerometer', device sensor through thePermissions API.

This feature may be blocked by aPermissions Policy set on your server.

EventTarget Sensor Accelerometer

Constructor

Accelerometer()Experimental

Creates a newAccelerometer object.

Instance properties

In addition to the properties listed below,Accelerometer inherits properties from its parent interfaces,Sensor andEventTarget.

Accelerometer.xRead onlyExperimental

Returns a double containing the acceleration of the device along the device's x axis.

Accelerometer.yRead onlyExperimental

Returns a double containing the acceleration of the device along the device's y axis.

Accelerometer.zRead onlyExperimental

Returns a double containing the acceleration of the device along the device's z axis.

Instance methods

Accelerometer doesn't have its own methods. However, it inherits methods from its parent interfaces,Sensor andEventTarget.

Events

Accelerometer doesn't have its own events. However, it inherits events from its parent interface,Sensor.

Example

Acceleration is typically read in thereading event callback. In the example below this occurs sixty times a second.

js
const acl = new Accelerometer({ frequency: 60 });acl.addEventListener("reading", () => {  console.log(`Acceleration along the X-axis ${acl.x}`);  console.log(`Acceleration along the Y-axis ${acl.y}`);  console.log(`Acceleration along the Z-axis ${acl.z}`);});acl.start();

Specifications

Specification
Accelerometer
# accelerometer-interface

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp