Skip to content

Springs

The createSpring function is an alternative to createTweened that often works better for values that are frequently changing.

In this example we have two springs — one representing the circle’s coordinates, and one representing its size.

import { createSpring } from "solivelte";
const [coords, setCoords] = createSpring({ x: 50, y: 50 });
const [size, setSize] = createSpring(10);

Both springs have default stiffness and damping values, which control the spring’s, well… springiness. We can specify our own initial values:

const [coords, setCoords] = createSpring(
{ x: 50, y: 50 },
{
stiffness: 0.1,
damping: 0.25,
}
);