my.onAccelerometerChange(function callback)
Note:
- This interface is supported since basic library version 1.9.0. Compatibility processing is required for earlier versions. See Mini Program base library to learn more.
- This interface is only supported in mPaaS 10.1.60 and later versions.
The interface is used to listen to the acceleration data. The callback interval is 500ms. After the interface is called, the listening is automatically started. You can use my.offAccelerometerChange
to stop listening.
Parameters
Parameter | Type | Description |
---|---|---|
function | callback | Callback function for the acceleration data change events. |
Callback return value
Parameter | Type | Description |
---|---|---|
x | Number | X axis |
y | Number | Y axis |
z | Number | Z axis |
Sample code
my.onAccelerometerChange(function(res) {
console.log(res.x)
console.log(res.y)
console.log(res.z)
})
my.offAccelerometerChange()
Note:
- This interface is supported since basic library version 1.9.0. Compatibility processing is required for earlier versions. See Mini Program base library to learn more.
- This interface is only supported in mPaaS 10.1.60 and later versions.
This interface is used to stop listening to acceleration data.
Sample code
my.offAccelerometerChange()
Whether to pass callback value or not
- If the callback value is not passed, the callbacks of all events will be removed. The sample code is as follows:
my.offAccelerometerChange();
- If the callback value is passed, only the corresponding callback is removed. The sample code is as follows:
my.offAccelerometerChange(this.callback);