Skip to content

Commit 5c88bb7

Browse files
committed
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
1 parent 6fc98de commit 5c88bb7

File tree

2 files changed

+80
-60
lines changed

2 files changed

+80
-60
lines changed

ui/jquery.effects.bounce.js

Lines changed: 62 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,78 +23,92 @@ $.effects.effect.bounce = function(o) {
2323
props = [ 'position', 'top', 'bottom', 'left', 'right' ],
2424
// defaults:
2525
mode = $.effects.setMode( el, o.mode || 'effect' ),
26+
showhide = rshowhide.test( mode ),
2627
direction = o.direction || 'up',
2728
distance = o.distance || 20,
28-
times = o.times || 5,
29-
speed = (o.duration || 250),
29+
times = o.times || 5,
30+
31+
// number of internal animations
32+
anims = times * 2 + showhide,
33+
speed = (o.duration || 250) / anims,
34+
easing = o.easing,
35+
3036
// utility:
3137
ref = ( direction == 'up' || direction == 'down' ) ? 'top' : 'left',
3238
motion = ( direction == 'up' || direction == 'left' ), // true is positive
33-
i, animation, animation1, animation2;
34-
39+
i,
40+
upAnim,
41+
downAnim,
42+
43+
// we will need to re-assemble the queue to stack our animations in place
44+
queue = el.queue(),
45+
queuelen = queue.length;
46+
3547
// Avoid touching opacity to prevent clearType and PNG issues in IE
36-
if ( rshowhide.test( mode ) ) {
48+
if ( showhide ) {
3749
props.push( 'opacity' );
3850
}
3951

4052
$.effects.save( el, props );
4153
el.show();
4254
$.effects.createWrapper( el ); // Create Wrapper
4355

56+
// default distance for the BIGGEST bounce is the outer Distance / 3
4457
if ( !distance ) {
4558
distance = el[ ref == 'top' ? 'outerHeight' : 'outerWidth' ]({ margin:true }) / 3;
4659
}
47-
if ( mode == 'show' ) el.css( 'opacity', 0 ).css( ref, motion ? -distance : distance ); // Shift
48-
if ( mode == 'hide' ) distance = distance / (times * 2);
49-
if ( mode != 'hide' ) times--;
50-
51-
// Animate
52-
if ( mode == 'show' ) {
53-
animation = {
54-
opacity: 1
55-
};
56-
animation[ ref ] = ( motion ? '+=' : '-=' ) + distance;
57-
el.animate( animation, speed / 2, o.easing);
58-
distance = distance / 2;
59-
times--;
60-
};
61-
62-
// Bounces
63-
for (i = 0; i < times; i++) {
64-
animation1 = {};
65-
animation2 = {};
66-
animation1[ ref ] = ( motion ? '-=' : '+=' ) + distance;
67-
animation2[ ref ] = ( motion ? '+=' : '-=' ) + distance;
68-
el.animate( animation1, speed / 2, o.easing ).animate( animation2, speed / 2, o.easing );
69-
distance = ( mode == 'hide' ) ? distance * 2 : distance / 2;
60+
61+
if ( mode == 'show' ) {
62+
upAnim = { opacity: 1 };
63+
upAnim[ ref ] = 0;
64+
65+
// fade and set the initial position if we are showing
66+
el.css( 'opacity', 0 )
67+
.css( ref, motion ? -distance*2 : distance*2 )
68+
.animate( upAnim, speed, easing );
69+
}
70+
71+
// start at the smallest distance if we are hiding
72+
if ( mode == 'hide' ) {
73+
distance = distance / ( ( times - 1 ) * 2 );
74+
}
75+
76+
// Bounces up then down (or reversed if motion) -- times * 2 animations happen here
77+
for ( i = 0; i < times; i++ ) {
78+
upAnim = {};
79+
downAnim = {};
80+
upAnim[ ref ] = ( motion ? '-=' : '+=' ) + distance;
81+
downAnim[ ref ] = ( motion ? '+=' : '-=' ) + distance;
82+
el.animate( upAnim, speed, easing )
83+
.animate( downAnim, speed, easing,
84+
( i == times - 1 ) && ( mode != "hide" ) ? finish : undefined );
85+
86+
distance = mode == 'hide' ? distance * 2 : distance / 2;
7087
}
7188

7289
// Last Bounce
7390
if ( mode == 'hide' ) {
74-
animation = {
75-
opacity: 0
76-
};
77-
animation[ ref ] = ( motion ? '-=' : '+=' ) + distance;
78-
el.animate( animation, speed / 2, o.easing, function(){
91+
upAnim = { opacity: 0 };
92+
upAnim[ ref ] = ( motion ? '-=' : '+=' ) + distance;
93+
94+
el.animate( upAnim, speed, easing, function(){
7995
el.hide();
80-
$.effects.restore( el, props );
81-
$.effects.removeWrapper( el );
82-
$.isFunction( o.complete ) && o.complete.apply( this, arguments );
96+
finish();
8397
});
84-
} else {
85-
animation1 = {};
86-
animation2 = {};
87-
animation1[ ref ] = ( motion ? '-=' : '+=' ) + distance;
88-
animation2[ ref ] = ( motion ? '+=' : '-=' ) + distance;
89-
el
90-
.animate( animation1, speed / 2, o.easing )
91-
.animate( animation2, speed / 2, o.easing, function() {
92-
$.effects.restore( el, props );
93-
$.effects.removeWrapper( el );
94-
$.isFunction( o.complete ) && o.complete.apply( this, arguments );
95-
});
98+
}
99+
100+
// inject all the animations we just queued to be first in line (after "inprogress")
101+
if ( queuelen > 1) {
102+
queue.splice.apply( queue,
103+
[ 1, 0 ].concat( queue.splice( queuelen, anims ) ) );
96104
}
97105
el.dequeue();
106+
107+
function finish() {
108+
$.effects.restore( el, props );
109+
$.effects.removeWrapper( el );
110+
$.isFunction( o.complete ) && o.complete.apply( el[ 0 ], arguments );
111+
}
98112
});
99113

100114
};

ui/jquery.effects.pulsate.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,26 @@ $.effects.effect.pulsate = function( o ) {
1616
return this.queue( function() {
1717
var elem = $( this ),
1818
mode = $.effects.setMode( elem, o.mode || 'show' ),
19-
times = ( ( o.times || 5 ) * 2 ) - 1,
20-
duration = o.duration / 2,
21-
isVisible = elem.is( ':visible' ),
19+
20+
// showing or hiding leave of the "last" time
21+
times = ( ( o.times || 5 ) * 2 ) - ( mode == "show" || mode == "hide" ),
22+
duration = o.duration / times,
23+
show = !elem.is( ":visible" ),
2224
animateTo = 0,
23-
i;
25+
i,
26+
queue = elem.queue(),
27+
queuelen = queue.length;
2428

25-
if ( !isVisible ) {
29+
if ( show ) {
2630
elem.css('opacity', 0).show();
2731
animateTo = 1;
2832
}
2933

30-
if ( ( mode == 'hide' && isVisible ) || ( mode == 'show' && !isVisible ) ) {
31-
times--;
32-
}
33-
34-
for ( i = 0; i < times; i++ ) {
34+
for ( i = 0; i < times - 1; i++ ) {
3535
elem.animate({
3636
opacity: animateTo
3737
}, duration, o.easing );
38-
animateTo = ( animateTo + 1 ) % 2;
38+
animateTo = 1 - animateTo;
3939
}
4040

4141
elem.animate({
@@ -45,7 +45,13 @@ $.effects.effect.pulsate = function( o ) {
4545
elem.hide();
4646
}
4747
(o.complete && o.complete.apply(this, arguments));
48-
}).dequeue();
48+
});
49+
50+
if ( queuelen > 1) {
51+
queue.splice.apply( queue,
52+
[ 1, 0 ].concat( queue.splice( queuelen, times ) ) );
53+
}
54+
elem.dequeue();
4955
});
5056
};
5157

0 commit comments

Comments
 (0)