* jQuery UI Effects Bounce 1.12.1
* Copyright jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
//>>description: Bounces an element horizontally or vertically n times.
//>>docs: http://api.jqueryui.com/bounce-effect/
//>>demos: http://jqueryui.com/effect/
if ( typeof define === "function" && define.amd ) {
// AMD. Register as an anonymous module.
return $.effects.define( "bounce", function( options, done ) {
var upAnim, downAnim, refValue,
direction = options.direction || "up",
distance = options.distance,
times = options.times || 5,
// Number of internal animations
anims = times * 2 + ( show || hide ? 1 : 0 ),
speed = options.duration / anims,
ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
motion = ( direction === "up" || direction === "left" ),
queuelen = element.queue().length;
$.effects.createPlaceholder( element );
refValue = element.css( ref );
// Default distance for the BIGGEST bounce is the outer Distance / 3
distance = element[ ref === "top" ? "outerHeight" : "outerWidth" ]() / 3;
downAnim = { opacity: 1 };
downAnim[ ref ] = refValue;
// If we are showing, force opacity 0 and set the initial position
// then do the "first" animation
.css( ref, motion ? -distance * 2 : distance * 2 )
.animate( downAnim, speed, easing );
// Start at the smallest distance if we are hiding
distance = distance / Math.pow( 2, times - 1 );
downAnim[ ref ] = refValue;
// Bounces up/down/left/right then back to 0 -- times * 2 animations happen here
for ( ; i < times; i++ ) {
upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
.animate( upAnim, speed, easing )
.animate( downAnim, speed, easing );
distance = hide ? distance * 2 : distance / 2;
// Last Bounce when Hiding
upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
element.animate( upAnim, speed, easing );
$.effects.unshift( element, queuelen, anims + 1 );