From fc552b0508a114abbe43ca6b3c95d5c9c14021dd Mon Sep 17 00:00:00 2001 From: Danny Date: Wed, 16 May 2018 10:16:13 +0200 Subject: [PATCH] set start variable outside of tick loop --- assets/js/components/CountWidget.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/assets/js/components/CountWidget.js b/assets/js/components/CountWidget.js index cf4b643..84113b2 100644 --- a/assets/js/components/CountWidget.js +++ b/assets/js/components/CountWidget.js @@ -32,10 +32,9 @@ class CountWidget extends Component { const setState = this.setState.bind(this); const startValue = isFinite(this.state.value) ? this.state.value : 0; const diff = toValue - startValue; - let startTime; + let startTime = performance.now(); const tick = function(t) { - if(!startTime) { startTime = t; } let progress = ( t - startTime ) / duration; let newValue = startValue + (easeOutQuint(progress) * diff); setState({ @@ -46,7 +45,7 @@ class CountWidget extends Component { window.requestAnimationFrame(tick); } } - + window.requestAnimationFrame(tick); }