2 * jQuery UI Effects Bounce 1.9.2
5 * Copyright 2012 jQuery Foundation and other contributors
6 * Released under the MIT license.
7 * http://jquery.org/license
9 * http://api.jqueryui.com/bounce-effect/
14 (function( $, undefined ) {
16 $.effects.effect.bounce = function( o, done ) {
18 props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
21 mode = $.effects.setMode( el, o.mode || "effect" ),
22 hide = mode === "hide",
23 show = mode === "show",
24 direction = o.direction || "up",
25 distance = o.distance,
28 // number of internal animations
29 anims = times * 2 + ( show || hide ? 1 : 0 ),
30 speed = o.duration / anims,
34 ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
35 motion = ( direction === "up" || direction === "left" ),
40 // we will need to re-assemble the queue to stack our animations in place
42 queuelen = queue.length;
44 // Avoid touching opacity to prevent clearType and PNG issues in IE
46 props.push( "opacity" );
49 $.effects.save( el, props );
51 $.effects.createWrapper( el ); // Create Wrapper
53 // default distance for the BIGGEST bounce is the outer Distance / 3
55 distance = el[ ref === "top" ? "outerHeight" : "outerWidth" ]() / 3;
59 downAnim = { opacity: 1 };
62 // if we are showing, force opacity 0 and set the initial position
63 // then do the "first" animation
64 el.css( "opacity", 0 )
65 .css( ref, motion ? -distance * 2 : distance * 2 )
66 .animate( downAnim, speed, easing );
69 // start at the smallest distance if we are hiding
71 distance = distance / Math.pow( 2, times - 1 );
76 // Bounces up/down/left/right then back to 0 -- times * 2 animations happen here
77 for ( i = 0; i < times; i++ ) {
79 upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
81 el.animate( upAnim, speed, easing )
82 .animate( downAnim, speed, easing );
84 distance = hide ? distance * 2 : distance / 2;
87 // Last Bounce when Hiding
89 upAnim = { opacity: 0 };
90 upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
92 el.animate( upAnim, speed, easing );
99 $.effects.restore( el, props );
100 $.effects.removeWrapper( el );
104 // inject all the animations we just queued to be first in line (after "inprogress")
106 queue.splice.apply( queue,
107 [ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) );