| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
(function( $, undefined ) { |
| 15 |
|
| 16 |
$.effects.effect.shake = function( o, done ) { |
| 17 |
|
| 18 |
var el = $( this ), |
| 19 |
props = [ "position", "top", "bottom", "left", "right", "height", "width" ], |
| 20 |
mode = $.effects.setMode( el, o.mode || "effect" ), |
| 21 |
direction = o.direction || "left", |
| 22 |
distance = o.distance || 20, |
| 23 |
times = o.times || 3, |
| 24 |
anims = times * 2 + 1, |
| 25 |
speed = Math.round(o.duration/anims), |
| 26 |
ref = (direction === "up" || direction === "down") ? "top" : "left", |
| 27 |
positiveMotion = (direction === "up" || direction === "left"), |
| 28 |
animation = {}, |
| 29 |
animation1 = {}, |
| 30 |
animation2 = {}, |
| 31 |
i, |
| 32 |
|
| 33 |
|
| 34 |
queue = el.queue(), |
| 35 |
queuelen = queue.length; |
| 36 |
|
| 37 |
$.effects.save( el, props ); |
| 38 |
el.show(); |
| 39 |
$.effects.createWrapper( el ); |
| 40 |
|
| 41 |
|
| 42 |
animation[ ref ] = ( positiveMotion ? "-=" : "+=" ) + distance; |
| 43 |
animation1[ ref ] = ( positiveMotion ? "+=" : "-=" ) + distance * 2; |
| 44 |
animation2[ ref ] = ( positiveMotion ? "-=" : "+=" ) + distance * 2; |
| 45 |
|
| 46 |
|
| 47 |
el.animate( animation, speed, o.easing ); |
| 48 |
|
| 49 |
|
| 50 |
for ( i = 1; i < times; i++ ) { |
| 51 |
el.animate( animation1, speed, o.easing ).animate( animation2, speed, o.easing ); |
| 52 |
} |
| 53 |
el |
| 54 |
.animate( animation1, speed, o.easing ) |
| 55 |
.animate( animation, speed / 2, o.easing ) |
| 56 |
.queue(function() { |
| 57 |
if ( mode === "hide" ) { |
| 58 |
el.hide(); |
| 59 |
} |
| 60 |
$.effects.restore( el, props ); |
| 61 |
$.effects.removeWrapper( el ); |
| 62 |
done(); |
| 63 |
}); |
| 64 |
|
| 65 |
|
| 66 |
if ( queuelen > 1) { |
| 67 |
queue.splice.apply( queue, |
| 68 |
[ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) ); |
| 69 |
} |
| 70 |
el.dequeue(); |
| 71 |
|
| 72 |
}; |
| 73 |
|
| 74 |
})(jQuery); |