40 |
aurelien |
1 |
/*
|
|
|
2 |
* jQuery UI Effects Shake 1.8.5
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
|
|
|
5 |
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
6 |
* http://jquery.org/license
|
|
|
7 |
*
|
|
|
8 |
* http://docs.jquery.com/UI/Effects/Shake
|
|
|
9 |
*
|
|
|
10 |
* Depends:
|
|
|
11 |
* jquery.effects.core.js
|
|
|
12 |
*/
|
|
|
13 |
(function( $, undefined ) {
|
|
|
14 |
|
|
|
15 |
$.effects.shake = function(o) {
|
|
|
16 |
|
|
|
17 |
return this.queue(function() {
|
|
|
18 |
|
|
|
19 |
// Create element
|
|
|
20 |
var el = $(this), props = ['position','top','left'];
|
|
|
21 |
|
|
|
22 |
// Set options
|
|
|
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
|
|
|
28 |
|
|
|
29 |
// Adjust
|
|
|
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';
|
|
|
34 |
|
|
|
35 |
// Animation
|
|
|
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;
|
|
|
40 |
|
|
|
41 |
// Animate
|
|
|
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);
|
|
|
45 |
};
|
|
|
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
|
|
|
50 |
});
|
|
|
51 |
el.queue('fx', function() { el.dequeue(); });
|
|
|
52 |
el.dequeue();
|
|
|
53 |
});
|
|
|
54 |
|
|
|
55 |
};
|
|
|
56 |
|
|
|
57 |
})(jQuery);
|