Socket
Socket
Sign inDemoInstall

shake.js

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    shake.js

A custom 'shake' event plugin for mobile web browsers using device accelerometer.


Version published
Weekly downloads
2.5K
decreased by-10.21%
Maintainers
1
Install size
10.1 kB
Created
Weekly downloads
 

Readme

Source

shake.js

A custom 'shake' event JavaScript plugin for mobile web browsers using device accelerometer.

Installation

  • Download: zip
  • NPM: npm install shake.js
  • Bower: bower install shake.js
  • Git: git clone https://github.com/alexgibson/shake.js

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:

var Shake = require('shake.js');

For AMD module:

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

In the browser:

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

Next, create a new Shake instance:

var myShakeEvent = new Shake({
    threshold: 15, // optional shake strength threshold
    timeout: 1000 // optional, determines the frequency of event generation
});

Start listening to device motion:

myShakeEvent.start();

Register a shake event listener on window with your callback:

window.addEventListener('shake', shakeEventDidOccur, false);

//function to call when shake occurs
function shakeEventDidOccur () {

    //put your own code here etc.
    alert('shake!');
}

You can stop listening for shake events like so:

window.removeEventListener('shake', shakeEventDidOccur, false);

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

Keywords

FAQs

Last updated on 22 Jul 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc