| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
( function( factory ) { |
| 17 |
"use strict"; |
| 18 |
|
| 19 |
if ( typeof define === "function" && define.amd ) { |
| 20 |
|
| 21 |
|
| 22 |
define( [ |
| 23 |
"jquery", |
| 24 |
"../version", |
| 25 |
"../effect" |
| 26 |
], factory ); |
| 27 |
} else { |
| 28 |
|
| 29 |
|
| 30 |
factory( jQuery ); |
| 31 |
} |
| 32 |
} )( function( $ ) { |
| 33 |
"use strict"; |
| 34 |
|
| 35 |
return $.effects.define( "shake", function( options, done ) { |
| 36 |
|
| 37 |
var i = 1, |
| 38 |
element = $( this ), |
| 39 |
direction = options.direction || "left", |
| 40 |
distance = options.distance || 20, |
| 41 |
times = options.times || 3, |
| 42 |
anims = times * 2 + 1, |
| 43 |
speed = Math.round( options.duration / anims ), |
| 44 |
ref = ( direction === "up" || direction === "down" ) ? "top" : "left", |
| 45 |
positiveMotion = ( direction === "up" || direction === "left" ), |
| 46 |
animation = {}, |
| 47 |
animation1 = {}, |
| 48 |
animation2 = {}, |
| 49 |
|
| 50 |
queuelen = element.queue().length; |
| 51 |
|
| 52 |
$.effects.createPlaceholder( element ); |
| 53 |
|
| 54 |
|
| 55 |
animation[ ref ] = ( positiveMotion ? "-=" : "+=" ) + distance; |
| 56 |
animation1[ ref ] = ( positiveMotion ? "+=" : "-=" ) + distance * 2; |
| 57 |
animation2[ ref ] = ( positiveMotion ? "-=" : "+=" ) + distance * 2; |
| 58 |
|
| 59 |
|
| 60 |
element.animate( animation, speed, options.easing ); |
| 61 |
|
| 62 |
|
| 63 |
for ( ; i < times; i++ ) { |
| 64 |
element |
| 65 |
.animate( animation1, speed, options.easing ) |
| 66 |
.animate( animation2, speed, options.easing ); |
| 67 |
} |
| 68 |
|
| 69 |
element |
| 70 |
.animate( animation1, speed, options.easing ) |
| 71 |
.animate( animation, speed / 2, options.easing ) |
| 72 |
.queue( done ); |
| 73 |
|
| 74 |
$.effects.unshift( element, queuelen, anims + 1 ); |
| 75 |
} ); |
| 76 |
|
| 77 |
} ); |