# additive-animation

> Animate object state with multiple concurrent animations

Latest version **0.1.0** (published 2014-11-11) · ISC license · 0 weekly downloads

## Install

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

## 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.1.0 |
| Published | 2014-11-11 |
| First published | 2014-11-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 47 |
| Author | Alexander |
| Maintainers | alexkuz |
| Keywords | additive, animation, interactive, transition |

## Links

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

## 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.1.0 (latest) — 2014-11-11

## README

Additive Animation
==================

This is a simple **npm** module which implements additive animation algorithm described here:

http://iosoteric.com/additive-animations-animatewithduration-in-ios-8/

or in this video:

https://developer.apple.com/videos/wwdc/2014/#236

It combines concurrent animations of the same object into one smooth continuous animation.

Demo
----

[**Here it is**](http://alexkuz.github.io/additive-animation/) (I hope you like cats).

Usage Example
-------------

Let's make smooth scrolling for window. Create animation object and provide the options. You need to provide at least **onRender** callback:

```
var AdditiveAnimation = require('additive-animation');

function onRender(state) {
  window.scrollTo(0, state.y);
};

var animation = new AdditiveAnimation({
  onRender: onRender
});
```

Now call **animate** method to start animation:

```
var fromState = { y: 0 };
var toState = { y: 1000 };
var duration = 1000;

animation.animate(fromState, toState, duration);
```

To add new animation with another final state, just call it again:

```
fromState = { y: window.scrollTop };
toState = { y: 2000 };

animation.animate(fromState, toState, duration);
```

API
---

#### animation = new AdditiveAnimation(options)

Creates animation object. Possible options:


Name | Signature | Description
:---------|:--------|:--------
**onRender** | `function(state)` | (**required**) a callback for rendering current animation state.
**onFinish** | `function(finalState)` | Fires after the last animation is completed.
**onCancel** | `function()` | Fires if animation is canceled.
**enabledRAF** | `bool` | Use `window.requestAnimationFrame` in animation loop. **True** by default. **Note**: if you use it, you should probably also use some polyfill, like this: https://github.com/cagosta/requestAnimationFrame
**fps** | `number` | If RAF is disabled, `setTimeout` is used in animation loop. Here you can define frequency (**60** frames per second by default).

#### animation.animate(fromState, toState, duration, easing)

Animates object state. `fromState` and `toState` are expected to be the objects with number values, e.g. `{ x: 100, y: 200 }`. `duration` is animation duration in milliseconds.

`easing` is a function used for easing. It could be a string (name of one of the functions described here: https://gist.github.com/gre/1650294 - for example, `'linear'` or `'easeInOutQuad'`) or your own function (assuming it's input and output values are in range `[0, 1]`). **'easeInOutQuad'** by default.

#### animation.isAnimating()

Returns `true` if there is an active animation.

#### animation.cancel()

Cancels current animation.

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