set start variable outside of tick loop

This commit is contained in:
Danny 2018-05-16 10:16:13 +02:00
parent 9f6684f0fb
commit fc552b0508

View File

@ -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);
}