2 * jQuery UI Effects Bounce 1.11.4
5 * Copyright jQuery Foundation and other contributors
6 * Released under the MIT license.
7 * http://jquery.org/license
9 * http://api.jqueryui.com/bounce-effect/
11 (function( factory
) {
12 if ( typeof define
=== "function" && define
.amd
) {
14 // AMD. Register as an anonymous module.
26 return $.effects
.effect
.bounce = function( o
, done
) {
28 props
= [ "position", "top", "bottom", "left", "right", "height", "width" ],
31 mode
= $.effects
.setMode( el
, o
.mode
|| "effect" ),
32 hide
= mode
=== "hide",
33 show
= mode
=== "show",
34 direction
= o
.direction
|| "up",
35 distance
= o
.distance
,
38 // number of internal animations
39 anims
= times
* 2 + ( show
|| hide
? 1 : 0 ),
40 speed
= o
.duration
/ anims
,
44 ref
= ( direction
=== "up" || direction
=== "down" ) ? "top" : "left",
45 motion
= ( direction
=== "up" || direction
=== "left" ),
50 // we will need to re-assemble the queue to stack our animations in place
52 queuelen
= queue
.length
;
54 // Avoid touching opacity to prevent clearType and PNG issues in IE
56 props
.push( "opacity" );
59 $.effects
.save( el
, props
);
61 $.effects
.createWrapper( el
); // Create Wrapper
63 // default distance for the BIGGEST bounce is the outer Distance / 3
65 distance
= el
[ ref
=== "top" ? "outerHeight" : "outerWidth" ]() / 3;
69 downAnim
= { opacity
: 1 };
72 // if we are showing, force opacity 0 and set the initial position
73 // then do the "first" animation
74 el
.css( "opacity", 0 )
75 .css( ref
, motion
? -distance
* 2 : distance
* 2 )
76 .animate( downAnim
, speed
, easing
);
79 // start at the smallest distance if we are hiding
81 distance
= distance
/ Math
.pow( 2, times
- 1 );
86 // Bounces up/down/left/right then back to 0 -- times * 2 animations happen here
87 for ( i
= 0; i
< times
; i
++ ) {
89 upAnim
[ ref
] = ( motion
? "-=" : "+=" ) + distance
;
91 el
.animate( upAnim
, speed
, easing
)
92 .animate( downAnim
, speed
, easing
);
94 distance
= hide
? distance
* 2 : distance
/ 2;
97 // Last Bounce when Hiding
99 upAnim
= { opacity
: 0 };
100 upAnim
[ ref
] = ( motion
? "-=" : "+=" ) + distance
;
102 el
.animate( upAnim
, speed
, easing
);
105 el
.queue(function() {
109 $.effects
.restore( el
, props
);
110 $.effects
.removeWrapper( el
);
114 // inject all the animations we just queued to be first in line (after "inprogress")
116 queue
.splice
.apply( queue
,
117 [ 1, 0 ].concat( queue
.splice( queuelen
, anims
+ 1 ) ) );