# animation-chain

> Animation Chain is a chaining library which utilizes the browser's `requestAnimationFrame` function in place of the usual `setTimeout`. This results in a much more accurate representation of time passed based on a delta time calculation. This can be usefu

Latest version **0.5.0** (published 2015-02-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install animation-chain
pnpm add animation-chain
yarn add animation-chain
bun add animation-chain
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2015-02-22 |
| First published | 2015-02-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | jnatalzia |
| Keywords | animation, animation-frame, css-animation, setTimeout |

## Links

- npm: https://www.npmjs.com/package/animation-chain
- Repository: https://github.com/jnatalzia/animation-chain
- Issues: https://github.com/jnatalzia/animation-chain/issues
- npm.io page: https://npm.io/package/animation-chain

## 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.0 (latest) — 2015-02-22

## README

# Animation Chain

Animation Chain is a chaining library which utilizes the browser's `requestAnimationFrame` function in place of the usual `setTimeout`. This results in a much more accurate representation of time passed based on a delta time calculation. This can be useful in timing class additions and removals based on CSS transition timings.

## Set Up ##
* Clone the repo
* Run `npm install` to install dependancies
* Run grunt to build the files into the `public/` dir

## Usage ##
`animation-chain` is invoked the same way that setTimeout is, with the `chainTo` function being added to easily integrate successive function calls. Like promises for certain amounts of time or events

```
setTimeout(function(){console.log('old')}, 500);
```
```
chain(function(){console.log('new')}, 500);
```

Here's a use case for a slightly longer timeout (useful in chaining animations through adding classes)

```
setTimeout(function() {
  el.classList.toggle("animation1");
  setTimeout(function() {
    el.classList.toggle("animation2");
  }, 500)
}, 500);
```
```
chain(function() {
  el.classList.toggle("animation1");
}, 500).chainTo(function() {
  el.classList.toggle("animation2");
}, 500);
```

All while being more performant based on animation frame usage

You can also tap into the transition and animation events like so

```
var chainObject = {
  selector: '.animating-el',
  callback: function() {
    console.log('animation-ended')
  },
  animationType: 'transition'
}

chain(chainObject);
```

### Options ###
`callback`: The callback to be executed when animation/timeout ends

`animationType`: Defaults to `transition` can also be `animation` if keyframes are being used

`time`: If using a timeout, the time to be used

`singleListener`: Defaults to `true`. Whether to only allow one event listener on a given element at a time. This can be useful when working with animations that can be stopped partway through so the event listener doesn't fire at the wrong end of the animation

### Fallbacks ###
If you're planning on utilizing timing events but want to support browsers that don't support those events, simply pass a `time` into your object with the correct amount of time the animation. The plugin will detect that those events are supported and default to the timeout

## Useful grunt tasks ##
* `lint` - Check your code

## Examples ##
Run `npm run examples` to start a server and view the different examples

This starts a server running at `localhost:8080/`

## Coming soon ##
~~Support for `transitionEnd` events~~

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