diff --git a/src/motion/spring.js b/src/motion/spring.js index 7d68377bd0..1b5413db63 100644 --- a/src/motion/spring.js +++ b/src/motion/spring.js @@ -117,20 +117,18 @@ export function spring(value, opts = {}) { last_time = window.performance.now(); settled = false; - task = loop(() => { - const time = window.performance.now(); - + task = loop(now=> { ({ value, settled } = tick_spring( velocity, value, target_value, spring.stiffness, spring.damping, - (time - last_time) * 60 / 1000, + (now - last_time) * 60 / 1000, threshold )); - last_time = time; + last_time = now; if (settled) { value = target_value; diff --git a/src/motion/tweened.js b/src/motion/tweened.js index 21ff8f70c7..49f1217a4e 100644 --- a/src/motion/tweened.js +++ b/src/motion/tweened.js @@ -76,9 +76,8 @@ export function tweened(value, defaults = {}) { const start = window.performance.now() + delay; let fn; - task = loop(() => { - const time = window.performance.now(); - if (time < start) return true; + task = loop(now => { + if (now < start) return true; if (!started) { fn = interpolate(value, new_value); @@ -91,7 +90,7 @@ export function tweened(value, defaults = {}) { previous_task = null; } - const elapsed = time - start; + const elapsed = now - start; if (elapsed > duration) { store.set(value = new_value);