Skip to content

Commit f7d63f7

Browse files
Merge pull request #1 from rikschennink/master
fix spring animation sometimes has negative start offset sveltejs#4468
2 parents a1cb70d + 8a09347 commit f7d63f7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/runtime/motion/spring.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Readable, writable } from 'svelte/store';
2-
import { loop, now, Task } from 'svelte/internal';
2+
import { loop, Task } from 'svelte/internal';
33
import { is_date } from './utils';
44

55
interface TickContext<T> {
@@ -85,7 +85,7 @@ export function spring<T=any>(value?: T, opts: SpringOpts = {}): Spring<T> {
8585

8686
if (value == null || opts.hard || (spring.stiffness >= 1 && spring.damping >= 1)) {
8787
cancel_task = true; // cancel any running animation
88-
last_time = now();
88+
last_time = null;
8989
last_value = new_value;
9090
store.set(value = target_value);
9191
return Promise.resolve();
@@ -96,11 +96,13 @@ export function spring<T=any>(value?: T, opts: SpringOpts = {}): Spring<T> {
9696
}
9797

9898
if (!task) {
99-
last_time = now();
99+
last_time = null;
100100
cancel_task = false;
101101

102102
task = loop(now => {
103103

104+
if (last_time === null) last_time = now;
105+
104106
if (cancel_task) {
105107
cancel_task = false;
106108
task = null;

0 commit comments

Comments
 (0)