| 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( "bounce", function( options, done ) { |
| 36 |
var upAnim, downAnim, refValue, |
| 37 |
element = $( this ), |
| 38 |
|
| 39 |
|
| 40 |
mode = options.mode, |
| 41 |
hide = mode === "hide", |
| 42 |
show = mode === "show", |
| 43 |
direction = options.direction || "up", |
| 44 |
distance = options.distance, |
| 45 |
times = options.times || 5, |
| 46 |
|
| 47 |
|
| 48 |
anims = times * 2 + ( show || hide ? 1 : 0 ), |
| 49 |
speed = options.duration / anims, |
| 50 |
easing = options.easing, |
| 51 |
|
| 52 |
|
| 53 |
ref = ( direction === "up" || direction === "down" ) ? "top" : "left", |
| 54 |
motion = ( direction === "up" || direction === "left" ), |
| 55 |
i = 0, |
| 56 |
|
| 57 |
queuelen = element.queue().length; |
| 58 |
|
| 59 |
$.effects.createPlaceholder( element ); |
| 60 |
|
| 61 |
refValue = element.css( ref ); |
| 62 |
|
| 63 |
|
| 64 |
if ( !distance ) { |
| 65 |
distance = element[ ref === "top" ? "outerHeight" : "outerWidth" ]() / 3; |
| 66 |
} |
| 67 |
|
| 68 |
if ( show ) { |
| 69 |
downAnim = { opacity: 1 }; |
| 70 |
downAnim[ ref ] = refValue; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
element |
| 75 |
.css( "opacity", 0 ) |
| 76 |
.css( ref, motion ? -distance * 2 : distance * 2 ) |
| 77 |
.animate( downAnim, speed, easing ); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
if ( hide ) { |
| 82 |
distance = distance / Math.pow( 2, times - 1 ); |
| 83 |
} |
| 84 |
|
| 85 |
downAnim = {}; |
| 86 |
downAnim[ ref ] = refValue; |
| 87 |
|
| 88 |
|
| 89 |
for ( ; i < times; i++ ) { |
| 90 |
upAnim = {}; |
| 91 |
upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance; |
| 92 |
|
| 93 |
element |
| 94 |
.animate( upAnim, speed, easing ) |
| 95 |
.animate( downAnim, speed, easing ); |
| 96 |
|
| 97 |
distance = hide ? distance * 2 : distance / 2; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
if ( hide ) { |
| 102 |
upAnim = { opacity: 0 }; |
| 103 |
upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance; |
| 104 |
|
| 105 |
element.animate( upAnim, speed, easing ); |
| 106 |
} |
| 107 |
|
| 108 |
element.queue( done ); |
| 109 |
|
| 110 |
$.effects.unshift( element, queuelen, anims + 1 ); |
| 111 |
} ); |
| 112 |
|
| 113 |
} ); |