Skip to main content
Version: 3.x

Taro.onAccelerometerChange(callback)

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

(callback: Callback) => void

Parameters

Callback

(res: Result) => void
PropertyType
resResult

Result

PropertyTypeDescription
xnumberX-axis
ynumberY-axis
znumberZ-axis

Sample Code

Taro.onAccelerometerChange(res => {
console.log(res.x)
console.log(res.y)
console.log(res.z)
})

API Support

APIWeChat Mini-ProgramH5React Native
Taro.onAccelerometerChange✔️✔️✔️