diff --git a/src/runtime/motion/spring.ts b/src/runtime/motion/spring.ts index 5845a13a57..c26b25b0ab 100644 --- a/src/runtime/motion/spring.ts +++ b/src/runtime/motion/spring.ts @@ -1,5 +1,5 @@ import { Readable, writable } from 'svelte/store'; -import { loop, now, Task } from 'svelte/internal'; +import { loop, Task } from 'svelte/internal'; import { is_date } from './utils'; interface TickContext { @@ -85,7 +85,7 @@ export function spring(value?: T, opts: SpringOpts = {}): Spring { if (value == null || opts.hard || (spring.stiffness >= 1 && spring.damping >= 1)) { cancel_task = true; // cancel any running animation - last_time = now(); + last_time = null; last_value = new_value; store.set(value = target_value); return Promise.resolve(); @@ -96,11 +96,13 @@ export function spring(value?: T, opts: SpringOpts = {}): Spring { } if (!task) { - last_time = now(); + last_time = null; cancel_task = false; task = loop(now => { + if (last_time === null) last_time = now; + if (cancel_task) { cancel_task = false; task = null;