- Taro.onAccelerometerChange(callback)
- 参数
- function callback(res)
- 参数
- object res
- 参数
- function callback(res)
- 示例代码
- API 支持度
- 参数
Taro.onAccelerometerChange(callback)
监听加速度数据事件。频率根据 startAccelerometer() 的 interval 参数。可使用 stopAccelerometer() 停止监听。
参数
function callback(res)
加速度数据事件的回调函数。
参数
object res
| Name | Type | Description |
|---|---|---|
| x | number | X 轴 |
| y | number | Y 轴 |
| z | number | Z 轴 |
示例代码
import Taro from '@tarojs/taro'Taro.onAccelerometerChange(res => {console.log(res.x)console.log(res.y)console.log(res.z)})
API 支持度
| API | 微信小程序 | H5 | React Native |
|---|---|---|---|
| Taro.onAccelerometerChange | ✔️ | ✔️ |
