2 * jQuery UI Effects Shake 1.8.24
4 * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about)
5 * Dual licensed under the MIT or GPL Version 2 licenses.
6 * http://jquery.org/license
8 * http://docs.jquery.com/UI/Effects/Shake
11 * jquery.effects.core.js
13 (function( $, undefined ) {
15 $.effects
.shake = function(o
) {
17 return this.queue(function() {
20 var el
= $(this), props
= ['position','top','bottom','left','right'];
23 var mode
= $.effects
.setMode(el
, o
.options
.mode
|| 'effect'); // Set Mode
24 var direction
= o
.options
.direction
|| 'left'; // Default direction
25 var distance
= o
.options
.distance
|| 20; // Default distance
26 var times
= o
.options
.times
|| 3; // Default # of times
27 var speed
= o
.duration
|| o
.options
.duration
|| 140; // Default speed per shake
30 $.effects
.save(el
, props
); el
.show(); // Save & Show
31 $.effects
.createWrapper(el
); // Create Wrapper
32 var ref
= (direction
== 'up' || direction
== 'down') ? 'top' : 'left';
33 var motion
= (direction
== 'up' || direction
== 'left') ? 'pos' : 'neg';
36 var animation
= {}, animation1
= {}, animation2
= {};
37 animation
[ref
] = (motion
== 'pos' ? '-=' : '+=') + distance
;
38 animation1
[ref
] = (motion
== 'pos' ? '+=' : '-=') + distance
* 2;
39 animation2
[ref
] = (motion
== 'pos' ? '-=' : '+=') + distance
* 2;
42 el
.animate(animation
, speed
, o
.options
.easing
);
43 for (var i
= 1; i
< times
; i
++) { // Shakes
44 el
.animate(animation1
, speed
, o
.options
.easing
).animate(animation2
, speed
, o
.options
.easing
);
46 el
.animate(animation1
, speed
, o
.options
.easing
).
47 animate(animation
, speed
/ 2, o
.options
.easing
, function(){ // Last shake
48 $.effects
.restore(el
, props
); $.effects
.removeWrapper(el
); // Restore
49 if(o
.callback
) o
.callback
.apply(this, arguments
); // Callback
51 el
.queue('fx', function() { el
.dequeue(); });