1.0.1 • Published 3 years ago

universal-accelerometer v1.0.1

Weekly downloads
11
License
BSD-3-Clause
Repository
-
Last release
3 years ago

title: accelerometer

accelerometer

npm

Accelerometer monitor and cancel.

Support

Install

$ npm install universal-accelerometer --save

Methods

onChange(callback): void

Monitoring acceleration data, the callback interval is 500ms, the interface calls will automatically start listening, can use offChange() to stop listening.

Parameters

PropertyTypeDescriptionSupport
callbackFunctionThe 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 '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:

import {accelerometer} from 'universal-api';
/**
 * iframe: true
 */
import React from 'react';
export default () => (
  <iframe style={{
      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'></iframe>
);
2.0.0-beta

3 years ago

1.0.1

4 years ago

1.0.0-beta.1

4 years ago