0.5.4 • Published 4 years ago

springframes v0.5.4

Weekly downloads
93
License
MIT
Repository
github
Last release
4 years ago

Springframes

A spring physics based keyframe generator to be used with Web Animation API. Fast and simple.

Install

Options

PropertyDefaultRequiredTypeDetails
dx-truenumberDisplacement on X axis
dy-truenumberDisplacement on Y axis
deg0falsenumberRotation (degrees)
scale1falsenumberScale (unstable)
reversefalsefalsebooleanRevert order of keyframes
stiffness500falsenumberSpring stiffness
damping50falsenumberSpring damping ratio
mass1falsenumberSpring mass

Usage

Simply import createSpringAnimation function and pass it displacement on X axis and Y axis. Other options are not required as you can see from the table above. You will get an object with keyframes and frames properties: keyframes are what you pass to KeyframeEffect and frames are used to calculate duration.

import { createSpringAnimation } from "springframes";

const { keyframes, frames } = createSpringAnimation({
  dx: 500,
  dy: 500,
  stiffness: 700,
  mass: 2,
  damping: 10,
});

if (keyframes.length > 0) {
  const kfEffect = new KeyframeEffect(square, keyframes, {
    duration: (frames / 60) * 1000,
    fill: "both",
    easing: "linear", // This must be linear!
    iterations: 1,
  });

  animation = new Animation(kfEffect);

  animation.play();
}

You can play with it here:

Edit on codesandbox

0.5.4

4 years ago

0.5.3

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.5.2

4 years ago

0.4.3

4 years ago

0.5.1

4 years ago

0.4.2

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago