@uni/accelerometer
v1.0.7
Published
[![npm](https://img.shields.io/npm/v/@uni/accelerometer.svg)](https://www.npmjs.com/package/@uni/accelerometer)
Downloads
3
Readme
accelerometer
Accelerometer monitor and cancel.
Support
Install
$ npm install @uni/accelerometer --save
Methods
onChange(callback): void
Monitoring acceleration data, the callback interval is 500ms, the interactive calls will automatically start listening, can use offChange() to stop listening.
Parameters
| Property | Type | Description | Support |
| -------- | -------- | ------------- | :-----: |
| callback | Function
| The callback function | |
offChange(): void
Stop listening for acceleration data.
是否需要传 callback 值
If the callback value is not passed, all event callbacks will be removed. The sample code is as follows:
accelerometer.offChange();
Pass the callback value and only remove the corresponding callback event. The sample code is as follows:
accelerometer.offChange(this.callback);
Example
import accelerometer from '@uni/accelerometer';
accelerometer.onChange(res => {
console.log(res.x);
console.log(res.y);
console.log(res.z);
});
accelerometer.offChange();
You can also import from the big package:
import {accelerometer} from '@uni/apis';