2012-02-27 00:49:51 +00:00
|
|
|
/*!
|
2024-10-30 16:22:18 +00:00
|
|
|
* jQuery UI Effects Bounce 1.14.1
|
2024-04-26 14:25:34 +00:00
|
|
|
* https://jqueryui.com
|
2008-06-06 20:08:52 +00:00
|
|
|
*
|
2022-07-19 07:36:55 +00:00
|
|
|
* Copyright OpenJS Foundation and other contributors
|
2012-08-09 14:13:24 +00:00
|
|
|
* Released under the MIT license.
|
2024-04-26 14:25:34 +00:00
|
|
|
* https://jquery.org/license
|
2008-06-06 20:08:52 +00:00
|
|
|
*/
|
2014-10-30 19:55:08 +00:00
|
|
|
|
|
|
|
//>>label: Bounce Effect
|
|
|
|
//>>group: Effects
|
|
|
|
//>>description: Bounces an element horizontally or vertically n times.
|
2024-04-26 14:25:34 +00:00
|
|
|
//>>docs: https://api.jqueryui.com/bounce-effect/
|
|
|
|
//>>demos: https://jqueryui.com/effect/
|
2014-10-30 19:55:08 +00:00
|
|
|
|
2015-03-18 14:39:12 +00:00
|
|
|
( function( factory ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
2015-03-18 14:39:12 +00:00
|
|
|
define( [
|
2013-07-12 16:40:48 +00:00
|
|
|
"jquery",
|
2015-07-15 02:01:41 +00:00
|
|
|
"../version",
|
|
|
|
"../effect"
|
2013-07-12 16:40:48 +00:00
|
|
|
], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
2021-06-06 22:58:12 +00:00
|
|
|
} )( function( $ ) {
|
|
|
|
"use strict";
|
2008-05-23 09:26:18 +00:00
|
|
|
|
2012-12-26 13:35:42 +00:00
|
|
|
return $.effects.define( "bounce", function( options, done ) {
|
|
|
|
var upAnim, downAnim, refValue,
|
|
|
|
element = $( this ),
|
2011-06-21 05:23:52 +00:00
|
|
|
|
2015-08-21 04:12:17 +00:00
|
|
|
// Defaults:
|
2012-12-26 13:35:42 +00:00
|
|
|
mode = options.mode,
|
2011-06-21 05:23:52 +00:00
|
|
|
hide = mode === "hide",
|
|
|
|
show = mode === "show",
|
2012-12-26 13:35:42 +00:00
|
|
|
direction = options.direction || "up",
|
|
|
|
distance = options.distance,
|
|
|
|
times = options.times || 5,
|
2011-06-21 05:23:52 +00:00
|
|
|
|
2015-08-21 04:12:17 +00:00
|
|
|
// Number of internal animations
|
2011-06-21 05:23:52 +00:00
|
|
|
anims = times * 2 + ( show || hide ? 1 : 0 ),
|
2012-12-26 13:35:42 +00:00
|
|
|
speed = options.duration / anims,
|
|
|
|
easing = options.easing,
|
2011-06-21 05:23:52 +00:00
|
|
|
|
2015-08-21 04:12:17 +00:00
|
|
|
// Utility:
|
2011-06-21 05:23:52 +00:00
|
|
|
ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
|
2012-04-19 01:57:51 +00:00
|
|
|
motion = ( direction === "up" || direction === "left" ),
|
2012-12-26 13:35:42 +00:00
|
|
|
i = 0,
|
2011-06-21 05:23:52 +00:00
|
|
|
|
2012-12-26 13:35:42 +00:00
|
|
|
queuelen = element.queue().length;
|
2011-06-21 05:23:52 +00:00
|
|
|
|
2012-12-26 13:35:42 +00:00
|
|
|
$.effects.createPlaceholder( element );
|
2011-06-21 05:23:52 +00:00
|
|
|
|
2012-12-26 13:35:42 +00:00
|
|
|
refValue = element.css( ref );
|
2011-06-21 05:23:52 +00:00
|
|
|
|
2015-08-21 04:12:17 +00:00
|
|
|
// Default distance for the BIGGEST bounce is the outer Distance / 3
|
2011-06-21 05:23:52 +00:00
|
|
|
if ( !distance ) {
|
2012-12-26 13:35:42 +00:00
|
|
|
distance = element[ ref === "top" ? "outerHeight" : "outerWidth" ]() / 3;
|
2011-06-21 05:23:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( show ) {
|
|
|
|
downAnim = { opacity: 1 };
|
2012-12-26 13:35:42 +00:00
|
|
|
downAnim[ ref ] = refValue;
|
2011-03-07 00:48:14 +00:00
|
|
|
|
2015-08-21 04:12:17 +00:00
|
|
|
// If we are showing, force opacity 0 and set the initial position
|
2011-06-21 05:23:52 +00:00
|
|
|
// then do the "first" animation
|
2012-12-26 13:35:42 +00:00
|
|
|
element
|
|
|
|
.css( "opacity", 0 )
|
2011-06-21 06:15:42 +00:00
|
|
|
.css( ref, motion ? -distance * 2 : distance * 2 )
|
2011-06-21 05:23:52 +00:00
|
|
|
.animate( downAnim, speed, easing );
|
|
|
|
}
|
|
|
|
|
2015-08-21 04:12:17 +00:00
|
|
|
// Start at the smallest distance if we are hiding
|
2011-06-21 05:23:52 +00:00
|
|
|
if ( hide ) {
|
|
|
|
distance = distance / Math.pow( 2, times - 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
downAnim = {};
|
2012-12-26 13:35:42 +00:00
|
|
|
downAnim[ ref ] = refValue;
|
2015-08-21 04:12:17 +00:00
|
|
|
|
2011-06-21 05:23:52 +00:00
|
|
|
// Bounces up/down/left/right then back to 0 -- times * 2 animations happen here
|
2012-12-26 13:35:42 +00:00
|
|
|
for ( ; i < times; i++ ) {
|
2011-06-21 05:23:52 +00:00
|
|
|
upAnim = {};
|
|
|
|
upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
|
|
|
|
|
2012-12-26 13:35:42 +00:00
|
|
|
element
|
|
|
|
.animate( upAnim, speed, easing )
|
2011-06-21 05:23:52 +00:00
|
|
|
.animate( downAnim, speed, easing );
|
|
|
|
|
|
|
|
distance = hide ? distance * 2 : distance / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Last Bounce when Hiding
|
|
|
|
if ( hide ) {
|
|
|
|
upAnim = { opacity: 0 };
|
|
|
|
upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
|
|
|
|
|
2012-12-26 13:35:42 +00:00
|
|
|
element.animate( upAnim, speed, easing );
|
2011-06-21 05:23:52 +00:00
|
|
|
}
|
2012-04-19 01:57:51 +00:00
|
|
|
|
2012-12-26 13:35:42 +00:00
|
|
|
element.queue( done );
|
2011-06-21 05:23:52 +00:00
|
|
|
|
2012-12-26 13:35:42 +00:00
|
|
|
$.effects.unshift( element, queuelen, anims + 1 );
|
2015-03-18 14:39:12 +00:00
|
|
|
} );
|
2008-05-23 09:26:18 +00:00
|
|
|
|
2021-06-06 22:58:12 +00:00
|
|
|
} );
|