GithubHelp home page GithubHelp logo

gaearon / additive-animation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alexkuz/additive-animation

2.0 2.0 1.0 121 KB

Additive animation npm module

Home Page: http://alexkuz.github.io/additive-animation/

License: MIT License

JavaScript 99.14% Makefile 0.86%

additive-animation's Introduction

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 (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.

additive-animation's People

Contributors

alexkuz avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

rubythonode

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.