title: Taro.onAccelerometerChange(callback)

sidebar_label: onAccelerometerChange

Listens on the acceleration data event. The frequency is based on the Taro.startAccelerometer() interval parameter. You can use Taro.stopAccelerometer() to stop listening.

Reference

Type

  1. (callback: Callback) => void

Parameters

Callback

  1. (res: Result) => void
Property Type
res Result

Result

Property Type Description
x number X-axis
y number Y-axis
z number Z-axis

Sample Code

  1. Taro.onAccelerometerChange(res => {
  2. console.log(res.x)
  3. console.log(res.y)
  4. console.log(res.z)
  5. })

API Support

API WeChat Mini-Program H5 React Native
Taro.onAccelerometerChange ✔️ ✔️ ✔️