Skip to content

Commit

Permalink
Ensure each tick gets it's own fxNow - Fixes #12837 - Thanks @chadparry
Browse files Browse the repository at this point in the history
Closes gh-1022
Closes gh-1021
(cherry picked from commit 781a5c0)
  • Loading branch information
gnarf committed Nov 8, 2012
1 parent 8e76cb7 commit c56732f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/effects.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ jQuery.fx.tick = function() {
timers = jQuery.timers, timers = jQuery.timers,
i = 0; i = 0;


fxNow = jQuery.now();

for ( ; i < timers.length; i++ ) { for ( ; i < timers.length; i++ ) {
timer = timers[ i ]; timer = timers[ i ];
// Checks the timer has not already been removed // Checks the timer has not already been removed
Expand All @@ -625,6 +627,7 @@ jQuery.fx.tick = function() {
if ( !timers.length ) { if ( !timers.length ) {
jQuery.fx.stop(); jQuery.fx.stop();
} }
fxNow = undefined;
}; };


jQuery.fx.timer = function( timer ) { jQuery.fx.timer = function( timer ) {
Expand Down
29 changes: 29 additions & 0 deletions test/unit/effects.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1811,6 +1811,35 @@ test( "Animate properly sets overflow hidden when animating width/height (#12117
}); });
}); });


test( "Each tick of the timer loop uses a fresh time (#12837)", function() {
var lastVal, current,
tmp = jQuery({
test: 0
});
expect( 3 );
tmp.animate({
test: 100
}, {
step: function( p, fx ) {
ok( fx.now !== lastVal, "Current value is not the last value: " + lastVal + " - " + fx.now );
lastVal = fx.now;
}
});
current = jQuery.now();
// intentionally empty, we want to spin wheels until the time changes.
while ( current === jQuery.now() ) { }

// now that we have a new time, run another tick
jQuery.fx.tick();

current = jQuery.now();
// intentionally empty, we want to spin wheels until the time changes.
while ( current === jQuery.now() ) { }

jQuery.fx.tick();
tmp.stop();
});

test( "Animations with 0 duration don't ease (#12273)", 1, function() { test( "Animations with 0 duration don't ease (#12273)", 1, function() {
jQuery.easing.test = function() { jQuery.easing.test = function() {
ok( false, "Called easing" ); ok( false, "Called easing" );
Expand Down

0 comments on commit c56732f

Please sign in to comment.