aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.effects.bounce.js
diff options
context:
space:
mode:
authorgnarf <gnarf@gnarf.net>2011-03-27 06:30:40 -0500
committergnarf <gnarf@gnarf.net>2011-03-27 06:30:52 -0500
commit5c88bb702fcde5294a4ab357d249fe892309b997 (patch)
tree7ade05afce4c03ad668b7ba6a8184adc01aff037 /ui/jquery.effects.bounce.js
parent6fc98deef03b91b0ea2ed51be2708bdd2c61d479 (diff)
downloadjquery-ui-5c88bb702fcde5294a4ab357d249fe892309b997.tar.gz
jquery-ui-5c88bb702fcde5294a4ab357d249fe892309b997.zip
effects.*: Normalizing animation time - 1000 ms effect should only take 1000 ms - Fixes #7067 - Also making sure the queued animations run DIRECTLY after the effect
Diffstat (limited to 'ui/jquery.effects.bounce.js')
-rw-r--r--ui/jquery.effects.bounce.js110
1 files changed, 62 insertions, 48 deletions
diff --git a/ui/jquery.effects.bounce.js b/ui/jquery.effects.bounce.js
index 8da0feb76..d329857c6 100644
--- a/ui/jquery.effects.bounce.js
+++ b/ui/jquery.effects.bounce.js
@@ -23,17 +23,29 @@ $.effects.effect.bounce = function(o) {
props = [ 'position', 'top', 'bottom', 'left', 'right' ],
// defaults:
mode = $.effects.setMode( el, o.mode || 'effect' ),
+ showhide = rshowhide.test( mode ),
direction = o.direction || 'up',
distance = o.distance || 20,
- times = o.times || 5,
- speed = (o.duration || 250),
+ times = o.times || 5,
+
+ // number of internal animations
+ anims = times * 2 + showhide,
+ speed = (o.duration || 250) / anims,
+ easing = o.easing,
+
// utility:
ref = ( direction == 'up' || direction == 'down' ) ? 'top' : 'left',
motion = ( direction == 'up' || direction == 'left' ), // true is positive
- i, animation, animation1, animation2;
-
+ i,
+ upAnim,
+ downAnim,
+
+ // we will need to re-assemble the queue to stack our animations in place
+ queue = el.queue(),
+ queuelen = queue.length;
+
// Avoid touching opacity to prevent clearType and PNG issues in IE
- if ( rshowhide.test( mode ) ) {
+ if ( showhide ) {
props.push( 'opacity' );
}
@@ -41,60 +53,62 @@ $.effects.effect.bounce = function(o) {
el.show();
$.effects.createWrapper( el ); // Create Wrapper
+ // default distance for the BIGGEST bounce is the outer Distance / 3
if ( !distance ) {
distance = el[ ref == 'top' ? 'outerHeight' : 'outerWidth' ]({ margin:true }) / 3;
}
- if ( mode == 'show' ) el.css( 'opacity', 0 ).css( ref, motion ? -distance : distance ); // Shift
- if ( mode == 'hide' ) distance = distance / (times * 2);
- if ( mode != 'hide' ) times--;
-
- // Animate
- if ( mode == 'show' ) {
- animation = {
- opacity: 1
- };
- animation[ ref ] = ( motion ? '+=' : '-=' ) + distance;
- el.animate( animation, speed / 2, o.easing);
- distance = distance / 2;
- times--;
- };
-
- // Bounces
- for (i = 0; i < times; i++) {
- animation1 = {};
- animation2 = {};
- animation1[ ref ] = ( motion ? '-=' : '+=' ) + distance;
- animation2[ ref ] = ( motion ? '+=' : '-=' ) + distance;
- el.animate( animation1, speed / 2, o.easing ).animate( animation2, speed / 2, o.easing );
- distance = ( mode == 'hide' ) ? distance * 2 : distance / 2;
+
+ if ( mode == 'show' ) {
+ upAnim = { opacity: 1 };
+ upAnim[ ref ] = 0;
+
+ // fade and set the initial position if we are showing
+ el.css( 'opacity', 0 )
+ .css( ref, motion ? -distance*2 : distance*2 )
+ .animate( upAnim, speed, easing );
+ }
+
+ // start at the smallest distance if we are hiding
+ if ( mode == 'hide' ) {
+ distance = distance / ( ( times - 1 ) * 2 );
+ }
+
+ // Bounces up then down (or reversed if motion) -- times * 2 animations happen here
+ for ( i = 0; i < times; i++ ) {
+ upAnim = {};
+ downAnim = {};
+ upAnim[ ref ] = ( motion ? '-=' : '+=' ) + distance;
+ downAnim[ ref ] = ( motion ? '+=' : '-=' ) + distance;
+ el.animate( upAnim, speed, easing )
+ .animate( downAnim, speed, easing,
+ ( i == times - 1 ) && ( mode != "hide" ) ? finish : undefined );
+
+ distance = mode == 'hide' ? distance * 2 : distance / 2;
}
// Last Bounce
if ( mode == 'hide' ) {
- animation = {
- opacity: 0
- };
- animation[ ref ] = ( motion ? '-=' : '+=' ) + distance;
- el.animate( animation, speed / 2, o.easing, function(){
+ upAnim = { opacity: 0 };
+ upAnim[ ref ] = ( motion ? '-=' : '+=' ) + distance;
+
+ el.animate( upAnim, speed, easing, function(){
el.hide();
- $.effects.restore( el, props );
- $.effects.removeWrapper( el );
- $.isFunction( o.complete ) && o.complete.apply( this, arguments );
+ finish();
});
- } else {
- animation1 = {};
- animation2 = {};
- animation1[ ref ] = ( motion ? '-=' : '+=' ) + distance;
- animation2[ ref ] = ( motion ? '+=' : '-=' ) + distance;
- el
- .animate( animation1, speed / 2, o.easing )
- .animate( animation2, speed / 2, o.easing, function() {
- $.effects.restore( el, props );
- $.effects.removeWrapper( el );
- $.isFunction( o.complete ) && o.complete.apply( this, arguments );
- });
+ }
+
+ // inject all the animations we just queued to be first in line (after "inprogress")
+ if ( queuelen > 1) {
+ queue.splice.apply( queue,
+ [ 1, 0 ].concat( queue.splice( queuelen, anims ) ) );
}
el.dequeue();
+
+ function finish() {
+ $.effects.restore( el, props );
+ $.effects.removeWrapper( el );
+ $.isFunction( o.complete ) && o.complete.apply( el[ 0 ], arguments );
+ }
});
};