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.
Type
(callback: Callback) => void
Parameters
Callback
(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
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 | ✔️ | ✔️ | ✔️ |