Physics Engine
Frame-rate independent springs. The base layer the rest of the motion stack is built on.
v2.0.0@magic-spells/physics-engine
Live demo
Or click the track. Move the sliders mid-flight.
Parameter Lab — drag tension and friction, watch the spring change under you.
About
Spring physics engine for smooth, natural animations. Drives a numeric value from start to end using a spring-damper model, emitting position and progress on every frame.
Features
- @magic-spells/event-emitter — the on/off/emit/removeAllListeners base class this engine extends. The only dependency, installed automatically with this package.
Usage
const spring = new PhysicsEngine({ attraction: 0.026, friction: 0.28 });
spring.on('change', ({ position, progress }) => {
element.style.transform = `translateX(${position}px)`;
});
await spring.animateTo(0, 400);About, features, usage and options are taken from the package README.