Skip to content

Commit 781a5c0

Browse files
committed
Ensure each tick gets it's own fxNow - Fixes #12837 - Thanks @chadparry
Closes jquerygh-1022 Closes jquerygh-1021
1 parent 6b14cef commit 781a5c0

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
@@ -612,6 +612,8 @@ jQuery.fx.tick = function() {
612612
timers = jQuery.timers,
613613
i = 0;
614614

615+
fxNow = jQuery.now();
616+
615617
for ( ; i < timers.length; i++ ) {
616618
timer = timers[ i ];
617619
// Checks the timer has not already been removed
@@ -623,6 +625,7 @@ jQuery.fx.tick = function() {
623625
if ( !timers.length ) {
624626
jQuery.fx.stop();
625627
}
628+
fxNow = undefined;
626629
};
627630

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

test/unit/effects.js

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

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

0 commit comments

Comments
 (0)