Giter Site home page Giter Site logo

animation-experiment's Introduction

Animation Experiment

This project contains an experimental library for creating interactive, interruptible animations. It will only animate css properties that can be hardware accelerated. This project is a work in progress and the API is still being developed. Complex animation sequences are not yet supported. I took inspiration from Greensock, the (still experimental) Web Animations API, and iOS's UIViewPropertyAnimator.

Getting Started

The library currently exposes one global: Animator. Initialize an Animator with a target DOM node, a starting and ending state, and a set of timing parameters.

var animator = new Animator(box, {
	from: { translateX: 0 },
	to:   { translateX: 100 }
}, {
	easing: 'ease-out',
	duration: 400
});

In addition to the standard CSS easing functions, the library allows you to make use of spring physics by modeling a Damped Harmonic Oscillator.

var animator = new Animator(box, {
	from: { translateX: 0 },
	to: { translateX: 100 }
}, {
	easing: 'spring',
	stiffness: 100,
	damping: 10,
	velocity: 0
});

The default is a "critically damped" spring. When spring physics are used, the duration property is ignored and the duration of the animation is computed based on the characteristics of the spring.

Animations can be played, paused, reversed, and seeked.

animator.play();
animator.pause();
animator.isReversed = true; // play backwards
animator.currentTime = 250; // seek (ms)

You can also interrupt an animation, and continue it towards its target using a new set of timing parameters. When the animation finishes, control is returned to the Animator's original timeline and the original timing parameters are restored.

animator.pause();
animator.continue({
	easing: 'ease-out',
	duration: 400
});

You can also manually "scrub" an animation's progress towards its target values. A timing function, like 'ease' controls the value of a css property as a function of time, by mapping both in the range 0.0 to 1.0:

Timing Function

By manipulating an animation's progress you are manipulating the y axis in this diagram, NOT time. For example, consider an animation that animates opacity from 1 to 0 in 400ms.

animator.progress = 0.5; // Animator is halfway towards its final values, opacity is 0.5

Adjusting an Animator's currentTime will result in different values for a css property at the same timestamp depending on the easing funciton used. But setting progress = 0.5 will ALWAYS set the animation to values halfway between the starting and ending values.

NOTE: Adjusting an animation's progress currently puts the Animator into the "stopped" state. continue must be called to re-initialize the Animator.

See the examples and API Documentation for further explanation.

Local Development

Working with the animation library requires the main js file located at dist/index.js.

To try out the library locally, first install dev dependencies:

npm install

A gulp task is provided that serves the project statically and sets up a watcher on the src folder which runs jshint and re-compiles the library via browserify using the ES2015 preset.

gulp serve

Open your browser to http://localhost:9000

Documentation

Full API documentation is also available by running a separate gulp task that serves the contents of the docs folder.

gulp docs

Open your browser to http://localhost:9001

animation-experiment's People

Watchers

 avatar  avatar

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.