--- title: accelerometer ---
---
title: accelerometer
---
Accelerometer monitor and cancel.
``bash`
$ npm install universal-accelerometer --save
Monitoring acceleration data, the callback interval is 500ms, the interface calls will automatically start listening, can use offChange() to stop listening.
#### Parameters
| Property | Type | Description | Support |
| -------- | -------- | ------------- | :-----: |
| callback | Function | The callback function |
|
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);
`js
import accelerometer from 'universal-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:
`js`
import {accelerometer} from 'universal-api';
`jsx | inline``
/**
* iframe: true
*/
import React from 'react';
export default () => (
boxShadow: '0 2px 15px rgba(0,0,0,0.1)',
width: '375px',
height: '700px'
}} src='https://herbox.online/p/109000004/app_1aKtEd7SK?previewZoom=100&view=preview&defaultPage=pages/universal-accelerometer/index&topSlider=false'>
);
