2012-02-27 00:49:51 +00:00
|
|
|
/*!
|
2008-09-04 22:03:30 +00:00
|
|
|
* jQuery UI Effects Bounce @VERSION
|
2012-07-04 13:08:08 +00:00
|
|
|
* http://jqueryui.com
|
2008-06-06 20:08:52 +00:00
|
|
|
*
|
2014-12-21 18:27:43 +00:00
|
|
|
* Copyright jQuery Foundation and other contributors
|
2012-08-09 14:13:24 +00:00
|
|
|
* Released under the MIT license.
|
2010-07-09 13:01:04 +00:00
|
|
|
* http://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.
|
|
|
|
//>>docs: http://api.jqueryui.com/bounce-effect/
|
|
|
|
//>>demos: http://jqueryui.com/effect/
|
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
(function( factory ) {
|
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
|
|
|
define([
|
|
|
|
"jquery",
|
2013-12-02 18:36:12 +00:00
|
|
|
"./effect"
|
2013-07-12 16:40:48 +00:00
|
|
|
], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
|
|
|
}(function( $ ) {
|
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
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
// number of internal animations
|
|
|
|
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
|
|
|
|
|
|
|
// utility:
|
|
|
|
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
|
|
|
|
|
|
|
// default distance for the BIGGEST bounce is the outer Distance / 3
|
|
|
|
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
|
|
|
|
2011-06-21 05:23:52 +00:00
|
|
|
// if we are showing, force opacity 0 and set the initial position
|
|
|
|
// 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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
// start at the smallest distance if we are hiding
|
|
|
|
if ( hide ) {
|
|
|
|
distance = distance / Math.pow( 2, times - 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
downAnim = {};
|
2012-12-26 13:35:42 +00:00
|
|
|
downAnim[ ref ] = refValue;
|
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 );
|
|
|
|
});
|
2008-05-23 09:26:18 +00:00
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
}));
|