# springframes

> A spring physics based keyframe generator

Latest version **0.5.4** (published 2020-08-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install springframes
pnpm add springframes
yarn add springframes
bun add springframes
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.4 |
| Published | 2020-08-09 |
| First published | 2020-08-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 27.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 31 |
| Author | Kirill Vasiltsov |
| Maintainers | jlkiri |
| Keywords | animation, transition, spring, css |

## Links

- npm: https://www.npmjs.com/package/springframes
- Repository: https://github.com/jlkiri/springframes
- Homepage: https://github.com/jlkiri/springframes#readme
- Issues: https://github.com/jlkiri/springframes/issues
- npm.io page: https://npm.io/package/springframes

## Alternatives

- [@luma.gl/experimental](https://npm.io/package/@luma.gl/experimental.md) — 77.1K weekly downloads
- [persona-harness](https://npm.io/package/persona-harness.md) — 4.7K weekly downloads
- [@tsparticles/effect-bubble](https://npm.io/package/@tsparticles/effect-bubble.md) — 4.6K weekly downloads
- [f3d](https://npm.io/package/f3d.md) — 730 weekly downloads
- [spark-html-motion](https://npm.io/package/spark-html-motion.md) — 298 weekly downloads

## Recent versions

- 0.5.4 (latest) — 2020-08-09
- 0.5.3 — 2020-08-09
- 0.5.2 — 2020-08-09
- 0.5.1 — 2020-08-09
- 0.5.0 — 2020-08-09
- 0.4.3 — 2020-08-09
- 0.4.2 — 2020-08-09
- 0.4.1 — 2020-08-09
- 0.4.0 — 2020-08-09
- 0.3.0 — 2020-08-09
- 0.2.0 — 2020-08-09
- 0.1.0 — 2020-08-09

## README

# Springframes

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

## Install

- Node: `npm install springframes`
- UMD: https://unpkg.com/springframes@latest/lib/springframes.umd.js

## Options

|  Property   | Default | Required |   Type    |          Details          |
| :---------: | :-----: | :------: | :-------: | :-----------------------: |
|    `dx`     |    -    |  `true`  | `number`  |  Displacement on X axis   |
|    `dy`     |    -    |  `true`  | `number`  |  Displacement on Y axis   |
|    `deg`    |   `0`   | `false`  | `number`  |    Rotation (degrees)     |
|   `scale`   |   `1`   | `false`  | `number`  |   Scale (**unstable**)    |
|  `reverse`  | `false` | `false`  | `boolean` | Revert order of keyframes |
| `stiffness` |  `500`  | `false`  | `number`  |     Spring stiffness      |
|  `damping`  |  `50`   | `false`  | `number`  |   Spring damping ratio    |
|   `mass`    |   `1`   | `false`  | `number`  |        Spring 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.

```js
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](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/simple-spring-animation-package-3yz48?fontsize=14&hidenavigation=1&theme=dark)

---
_Source: https://npm.io/package/springframes · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
