jquery.ios-shake icon indicating copy to clipboard operation
jquery.ios-shake copied to clipboard

A jQuery plugin that detects a 'shake' event using Safari's accelerometer support in iOS 4.2+.

trafficstars

h1. jQuery iOS Shake Detector

Note: this library isn't under active development. You may want to check out "this fork":https://github.com/LinusU/deviceshake.js from Linus Unnebäck instead.

A jQuery plugin that detects a 'shake' event using Safari's accelerometer support in iOS 4.2+.

jquery.ios-shake is a simple-to-use jQuery plugin that monitors the iPhone/iPad's accelerometer in order to detect the user "shaking" the device. The goal of this script is to provide robust shake detection and minimize the chances of triggering spurious shake events.

Click "here":http://labs.joviancore.com/jquery-ios-shake/ for a demo.

This is the minimum code required to detect a shake:

pre..

p. And, if you want to customize a bit more, here's an example with all the options. You can raise @violence@ to decrease sensitivity or decrease the @debounce@ if you need to detect shakes faster than one per second. (I'd leave the other options out unless you have some really specific application that's not working with the default settings.) The @debug@ and @supported@ options allow you to pass @div@ IDs to ios-shake so that it can place some specific content on your page. See example.html for details.

pre.. $.shake({ debug: "#debugdiv", // debug div id supported: "#notsupporteddiv", // not supported message div violence: 3.0, // single shake sensitivity hf: 0.2, // high-pass filter constant shakethreshold: 5, // number of single shakes required to fire a shake event debounce: 1000, // delay between shake events (in ms) callback: function() { yourFunction(); } });