Skip to content

Commit c56732f

Browse files
committed
Ensure each tick gets it's own fxNow - Fixes #12837 - Thanks @chadparry
Closes jquerygh-1022 Closes jquerygh-1021 (cherry picked from commit 781a5c0)
1 parent 8e76cb7 commit c56732f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/effects.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,8 @@ jQuery.fx.tick = function() {
614614
timers = jQuery.timers,
615615
i = 0;
616616

617+
fxNow = jQuery.now();
618+
617619
for ( ; i < timers.length; i++ ) {
618620
timer = timers[ i ];
619621
// Checks the timer has not already been removed
@@ -625,6 +627,7 @@ jQuery.fx.tick = function() {
625627
if ( !timers.length ) {
626628
jQuery.fx.stop();
627629
}
630+
fxNow = undefined;
628631
};
629632

630633
jQuery.fx.timer = function( timer ) {

test/unit/effects.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,35 @@ test( "Animate properly sets overflow hidden when animating width/height (#12117
18111811
});
18121812
});
18131813

1814+
test( "Each tick of the timer loop uses a fresh time (#12837)", function() {
1815+
var lastVal, current,
1816+
tmp = jQuery({
1817+
test: 0
1818+
});
1819+
expect( 3 );
1820+
tmp.animate({
1821+
test: 100
1822+
}, {
1823+
step: function( p, fx ) {
1824+
ok( fx.now !== lastVal, "Current value is not the last value: " + lastVal + " - " + fx.now );
1825+
lastVal = fx.now;
1826+
}
1827+
});
1828+
current = jQuery.now();
1829+
// intentionally empty, we want to spin wheels until the time changes.
1830+
while ( current === jQuery.now() ) { }
1831+
1832+
// now that we have a new time, run another tick
1833+
jQuery.fx.tick();
1834+
1835+
current = jQuery.now();
1836+
// intentionally empty, we want to spin wheels until the time changes.
1837+
while ( current === jQuery.now() ) { }
1838+
1839+
jQuery.fx.tick();
1840+
tmp.stop();
1841+
});
1842+
18141843
test( "Animations with 0 duration don't ease (#12273)", 1, function() {
18151844
jQuery.easing.test = function() {
18161845
ok( false, "Called easing" );

0 commit comments

Comments
 (0)