ShakeProgress
ShakeProgress
aggregates Shake
events based on a minimum number of shakes and minimum amount of time since shaking began. It returns a progress
value that starts at 0
and increases as the device is shaken until progress
reaches a value of 1
. At this time, the shake gesture is considered complete. The API only fires when the progress
is updated. ShakeProgress
relies on the device's Accelerometer
sensor.
Example
var shakeProgress = new MotionStack.ShakeProgress({
minShakes: 10,
minTime: 1000,
direction: "all"
});
shakeProgress.start(function (e) {
console.log(e.progress);
if (e.progress == 1) {
shakeProgress.stop();
}
});
Constructor
new MotionStack.ShakeProgress([options])
Create a new ShakeProgress instance object.
Argument | Type | Description |
---|---|---|
options |
Object |
Options to pass in for the new ShakeProgress instance (optional)
|
var shakeProgress = new MotionStack.ShakeProgress({
minShakes: 10,
minTime: 1000
});
Instance Methods
start(callback, [context])
Start receiving shake progress updates.
Argument | Type | Description |
---|---|---|
callback |
Function | Callback function that receives an object as an argument
|
context |
Object | Context in which to invoke the callback (optional). |
shakeProgress.start(function(e) {
console.log(e.progress);
});
stop()
Stop shakeProgress updates.
shakeProgress.stop();