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
(callback: Callback) => void
Parameters
Callback
(res: Result) => void
Result
Property |
Type |
Description |
x |
number |
X-axis |
y |
number |
Y-axis |
z |
number |
Z-axis |
Sample Code
Taro.onAccelerometerChange(res => {
console.log(res.x)
console.log(res.y)
console.log(res.z)
})
API Support
API |
WeChat Mini-Program |
H5 |
React Native |
Taro.onAccelerometerChange |
✔️ |
✔️ |
✔️ |