Skip to content

Commit 783f134

Browse files
committed
effects: Updating bounce/pulsate/shake to fire callbacks before the next anim starts
1 parent 27a7dee commit 783f134

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

ui/jquery.effects.bounce.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,8 @@ $.effects.effect.bounce = function(o) {
7979
upAnim = {};
8080
upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
8181

82-
// add the finish callback to the last animation if we aren't hiding
8382
el.animate( upAnim, speed, easing )
84-
.animate( downAnim, speed, easing,
85-
( ( i === times - 1 ) && !hide ) ? finish : undefined );
83+
.animate( downAnim, speed, easing );
8684

8785
distance = hide ? distance * 2 : distance / 2;
8886
}
@@ -92,24 +90,25 @@ $.effects.effect.bounce = function(o) {
9290
upAnim = { opacity: 0 };
9391
upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
9492

95-
el.animate( upAnim, speed, easing, function(){
96-
el.hide();
97-
finish();
98-
});
93+
el.animate( upAnim, speed, easing );
9994
}
100-
101-
function finish() {
95+
96+
el.queue( function( next ) {
97+
if ( hide ) {
98+
el.hide();
99+
}
102100
$.effects.restore( el, props );
103101
$.effects.removeWrapper( el );
104102
if ( o.complete ) {
105103
o.complete.apply( el[ 0 ] );
106104
}
107-
}
105+
next();
106+
});
108107

109108
// inject all the animations we just queued to be first in line (after "inprogress")
110109
if ( queuelen > 1) {
111110
queue.splice.apply( queue,
112-
[ 1, 0 ].concat( queue.splice( queuelen, anims ) ) );
111+
[ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) );
113112
}
114113
next();
115114

ui/jquery.effects.pulsate.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,22 @@ $.effects.effect.pulsate = function( o ) {
4343

4444
elem.animate({
4545
opacity: animateTo
46-
}, duration, o.easing, function() {
46+
}, duration, o.easing);
47+
48+
elem.queue( function( next ) {
4749
if ( hide ) {
4850
elem.hide();
4951
}
5052
if ( o.complete ) {
5153
o.complete.apply( this );
5254
}
55+
next();
5356
});
5457

5558
// We just queued up "anims" animations, we need to put them next in the queue
5659
if ( queuelen > 1) {
5760
queue.splice.apply( queue,
58-
[ 1, 0 ].concat( queue.splice( queuelen, anims ) ) );
61+
[ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) );
5962
}
6063
next();
6164
});

ui/jquery.effects.shake.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,21 @@ $.effects.effect.shake = function( o ) {
5454
};
5555
el
5656
.animate( animation1, speed, o.easing )
57-
.animate( animation, speed / 2, o.easing, function() {
57+
.animate( animation, speed / 2, o.easing )
58+
.queue( function( next ) {
5859
if ( mode === "hide" ) {
5960
el.hide();
6061
}
61-
// Last shake
6262
$.effects.restore( el, props );
6363
$.effects.removeWrapper( el );
6464
$.isFunction( o.complete ) && o.complete.apply( this, arguments );
65+
next();
6566
});
6667

6768
// inject all the animations we just queued to be first in line (after "inprogress")
6869
if ( queuelen > 1) {
6970
queue.splice.apply( queue,
70-
[ 1, 0 ].concat( queue.splice( queuelen, anims ) ) );
71+
[ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) );
7172
}
7273
el.dequeue();
7374
});

0 commit comments

Comments
 (0)