Skip to content

Commit

Permalink
effects.*: Normalizing animation time - 1000 ms effect should only ta…
Browse files Browse the repository at this point in the history
…ke 1000 ms - Fixes #7067 - Also making sure the queued animations run DIRECTLY after the effect
  • Loading branch information
gnarf committed Mar 27, 2011
1 parent 6fc98de commit 5c88bb7
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 60 deletions.
110 changes: 62 additions & 48 deletions ui/jquery.effects.bounce.js
Expand Up @@ -23,78 +23,92 @@ $.effects.effect.bounce = function(o) {
props = [ 'position', 'top', 'bottom', 'left', 'right' ], props = [ 'position', 'top', 'bottom', 'left', 'right' ],
// defaults: // defaults:
mode = $.effects.setMode( el, o.mode || 'effect' ), mode = $.effects.setMode( el, o.mode || 'effect' ),
showhide = rshowhide.test( mode ),
direction = o.direction || 'up', direction = o.direction || 'up',
distance = o.distance || 20, distance = o.distance || 20,
times = o.times || 5, times = o.times || 5,
speed = (o.duration || 250),
// number of internal animations
anims = times * 2 + showhide,
speed = (o.duration || 250) / anims,
easing = o.easing,

// utility: // utility:
ref = ( direction == 'up' || direction == 'down' ) ? 'top' : 'left', ref = ( direction == 'up' || direction == 'down' ) ? 'top' : 'left',
motion = ( direction == 'up' || direction == 'left' ), // true is positive 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 // Avoid touching opacity to prevent clearType and PNG issues in IE
if ( rshowhide.test( mode ) ) { if ( showhide ) {
props.push( 'opacity' ); props.push( 'opacity' );
} }


$.effects.save( el, props ); $.effects.save( el, props );
el.show(); el.show();
$.effects.createWrapper( el ); // Create Wrapper $.effects.createWrapper( el ); // Create Wrapper


// default distance for the BIGGEST bounce is the outer Distance / 3
if ( !distance ) { if ( !distance ) {
distance = el[ ref == 'top' ? 'outerHeight' : 'outerWidth' ]({ margin:true }) / 3; 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 == 'show' ) {
if ( mode != 'hide' ) times--; upAnim = { opacity: 1 };

upAnim[ ref ] = 0;
// Animate
if ( mode == 'show' ) { // fade and set the initial position if we are showing
animation = { el.css( 'opacity', 0 )
opacity: 1 .css( ref, motion ? -distance*2 : distance*2 )
}; .animate( upAnim, speed, easing );
animation[ ref ] = ( motion ? '+=' : '-=' ) + distance; }
el.animate( animation, speed / 2, o.easing);
distance = distance / 2; // start at the smallest distance if we are hiding
times--; if ( mode == 'hide' ) {
}; distance = distance / ( ( times - 1 ) * 2 );

}
// Bounces
for (i = 0; i < times; i++) { // Bounces up then down (or reversed if motion) -- times * 2 animations happen here
animation1 = {}; for ( i = 0; i < times; i++ ) {
animation2 = {}; upAnim = {};
animation1[ ref ] = ( motion ? '-=' : '+=' ) + distance; downAnim = {};
animation2[ ref ] = ( motion ? '+=' : '-=' ) + distance; upAnim[ ref ] = ( motion ? '-=' : '+=' ) + distance;
el.animate( animation1, speed / 2, o.easing ).animate( animation2, speed / 2, o.easing ); downAnim[ ref ] = ( motion ? '+=' : '-=' ) + distance;
distance = ( mode == 'hide' ) ? distance * 2 : distance / 2; 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 // Last Bounce
if ( mode == 'hide' ) { if ( mode == 'hide' ) {
animation = { upAnim = { opacity: 0 };
opacity: 0 upAnim[ ref ] = ( motion ? '-=' : '+=' ) + distance;
};
animation[ ref ] = ( motion ? '-=' : '+=' ) + distance; el.animate( upAnim, speed, easing, function(){
el.animate( animation, speed / 2, o.easing, function(){
el.hide(); el.hide();
$.effects.restore( el, props ); finish();
$.effects.removeWrapper( el );
$.isFunction( o.complete ) && o.complete.apply( this, arguments );
}); });
} else { }
animation1 = {};
animation2 = {}; // inject all the animations we just queued to be first in line (after "inprogress")
animation1[ ref ] = ( motion ? '-=' : '+=' ) + distance; if ( queuelen > 1) {
animation2[ ref ] = ( motion ? '+=' : '-=' ) + distance; queue.splice.apply( queue,
el [ 1, 0 ].concat( queue.splice( queuelen, anims ) ) );
.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 );
});
} }
el.dequeue(); el.dequeue();

function finish() {
$.effects.restore( el, props );
$.effects.removeWrapper( el );
$.isFunction( o.complete ) && o.complete.apply( el[ 0 ], arguments );
}
}); });


}; };
Expand Down
30 changes: 18 additions & 12 deletions ui/jquery.effects.pulsate.js
Expand Up @@ -16,26 +16,26 @@ $.effects.effect.pulsate = function( o ) {
return this.queue( function() { return this.queue( function() {
var elem = $( this ), var elem = $( this ),
mode = $.effects.setMode( elem, o.mode || 'show' ), mode = $.effects.setMode( elem, o.mode || 'show' ),
times = ( ( o.times || 5 ) * 2 ) - 1,
duration = o.duration / 2, // showing or hiding leave of the "last" time
isVisible = elem.is( ':visible' ), times = ( ( o.times || 5 ) * 2 ) - ( mode == "show" || mode == "hide" ),
duration = o.duration / times,
show = !elem.is( ":visible" ),
animateTo = 0, animateTo = 0,
i; i,
queue = elem.queue(),
queuelen = queue.length;


if ( !isVisible ) { if ( show ) {
elem.css('opacity', 0).show(); elem.css('opacity', 0).show();
animateTo = 1; animateTo = 1;
} }


if ( ( mode == 'hide' && isVisible ) || ( mode == 'show' && !isVisible ) ) { for ( i = 0; i < times - 1; i++ ) {
times--;
}

for ( i = 0; i < times; i++ ) {
elem.animate({ elem.animate({
opacity: animateTo opacity: animateTo
}, duration, o.easing ); }, duration, o.easing );
animateTo = ( animateTo + 1 ) % 2; animateTo = 1 - animateTo;
} }


elem.animate({ elem.animate({
Expand All @@ -45,7 +45,13 @@ $.effects.effect.pulsate = function( o ) {
elem.hide(); elem.hide();
} }
(o.complete && o.complete.apply(this, arguments)); (o.complete && o.complete.apply(this, arguments));
}).dequeue(); });

if ( queuelen > 1) {
queue.splice.apply( queue,
[ 1, 0 ].concat( queue.splice( queuelen, times ) ) );
}
elem.dequeue();
}); });
}; };


Expand Down

0 comments on commit 5c88bb7

Please sign in to comment.