JSPM

@zouloux/shake

1.3.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q20200F
  • License MIT

Shake event detector for mobile web browsers using device accelerometer. Forked from shake.js.

Package Exports

  • @zouloux/shake

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@zouloux/shake) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

shake.js Fork

This fork does not use event system, but rather use a classic handler. We can now have as many Shake object as we want, and we also know which one fired.

Forked from

  • Git: git clone https://github.com/alexgibson/shake.js

Installation

  • Download: zip
  • NPM: npm install @zouloux/shake

Dependencies

Your web browser must support the devicemotion event for this plugin to work. Shake.js uses built-in feature detection to determine if it can run in your web browser. It will terminate silently on non-supporting browsers.

http://w3c.github.io/deviceorientation/spec-source-orientation.html

Setup

For CommonJS using NPM:

const Shake = require('@zouloux/shake');

For AMD module:

define(['./shake'], function(Shake) {
    // ...
});

In the browser:

<script src="shake.js"></script>

Next, create a new Shake instance:

const myShakeEvent = new Shake({
    threshold: 15, // optional shake strength threshold
    timeout: 1000, // optional, determines the frequency of event generation
    handler: () => // required, called when shake is detected
    {
        console.log('Shake detected !');
    }
});

Start listening to device motion:

myShakeEvent.start();

To stop listening to device motion, you can call:

myShakeEvent.stop();

Supported web browsers/devices

  • iOS Safari 4.2.1 (and above)
  • Android 4.0.3 (default browser)
  • Chrome 41+ for Android
  • Opera Mobile (Android)
  • BlackBerry PlayBook 2.0
  • Firefox for Android
  • FirefoxOS Devices