2 * jQuery UI Effects Bounce 1.12.1
5 * Copyright jQuery Foundation and other contributors
6 * Released under the MIT license.
7 * http://jquery.org/license
10 //>>label: Bounce Effect
12 //>>description: Bounces an element horizontally or vertically n times.
13 //>>docs: http://api.jqueryui.com/bounce-effect/
14 //>>demos: http://jqueryui.com/effect/
16 ( function( factory ) {
17 if ( typeof define === "function" && define.amd ) {
19 // AMD. Register as an anonymous module.
32 return $.effects.define( "bounce", function( options, done ) {
33 var upAnim, downAnim, refValue,
38 hide = mode === "hide",
39 show = mode === "show",
40 direction = options.direction || "up",
41 distance = options.distance,
42 times = options.times || 5,
44 // Number of internal animations
45 anims = times * 2 + ( show || hide ? 1 : 0 ),
46 speed = options.duration / anims,
47 easing = options.easing,
50 ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
51 motion = ( direction === "up" || direction === "left" ),
54 queuelen = element.queue().length;
56 $.effects.createPlaceholder( element );
58 refValue = element.css( ref );
60 // Default distance for the BIGGEST bounce is the outer Distance / 3
62 distance = element[ ref === "top" ? "outerHeight" : "outerWidth" ]() / 3;
66 downAnim = { opacity: 1 };
67 downAnim[ ref ] = refValue;
69 // If we are showing, force opacity 0 and set the initial position
70 // then do the "first" animation
73 .css( ref, motion ? -distance * 2 : distance * 2 )
74 .animate( downAnim, speed, easing );
77 // Start at the smallest distance if we are hiding
79 distance = distance / Math.pow( 2, times - 1 );
83 downAnim[ ref ] = refValue;
85 // Bounces up/down/left/right then back to 0 -- times * 2 animations happen here
86 for ( ; i < times; i++ ) {
88 upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
91 .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 element.animate( upAnim, speed, easing );
105 element.queue( done );
107 $.effects.unshift( element, queuelen, anims + 1 );