A custom 'shake' event plugin for mobile web browsers using device accelerometer.
See the codeA custom 'shake' event JavaScript plugin for mobile web browsers using device accelerometer.
npm install shake.jsbower install shake.jsgit clone https://github.com/alexgibson/shake.jsYour 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
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();
Overall
Maintained
Code review
npm
Latest release
Releases this year
87 followers · starred Jan 2015
82 followers · starred Jun 2015
156 followers · starred Oct 2013
711 followers · starred Nov 2010
A custom 'shake' event plugin for mobile web browsers using device accelerometer.
See the codeA custom 'shake' event JavaScript plugin for mobile web browsers using device accelerometer.
npm install shake.jsbower install shake.jsgit clone https://github.com/alexgibson/shake.jsYour 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
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();
Overall
Maintained
Code review
npm
Latest release
Releases this year
87 followers · starred Jan 2015
82 followers · starred Jun 2015
156 followers · starred Oct 2013
711 followers · starred Nov 2010