Giter VIP home page Giter VIP logo

nanimation's Introduction

nAnimation

generic javascript animation library

http://imthenachoman.github.io/nAnimation/

Table of Contents

  1. Overview
  2. Credits
  3. How To Use
    1. CDN
    2. To Start An Animation
    3. To End An Animation
    4. To Get An Array Of The Available Easing Functions
  4. Example

Overview

There are a lot of great JavaScript animation libraries but all of them were either too complex or bulky for my needs. They all offered a host/slew of features that I didn't need. So I set out to write something simpler for myself. I ended up with nAnimation.

nAnimation doesn't really do any kind of animation; it lets you run a function an X # of times for a Y duration using an optional easing function. The function is called on each frame and can do whatever you need/want. At each frame/call the function is passed one paramater: a rate. The rate is a number between 0 and 1 and represents the % complete for each frame/call. (However, it is possible that some of the easing functions will result in a number larger then 1 during the duration.) The rate will always be 0 at the first frame/call and 1 at the last frame/call.

You can, in turn, use rate to do anything, including animations. For example, if the function sets the width of an element to be rate * width then the element will grow from 0 to width over the duration.

Credits

I didn't really actually create anything special; I was able to piece together different things I found online to do what I need. The resources I used:

  1. requestAnimationFrame from https://gist.github.com/paulirish/1579671
  2. a cool animation wrapper by Dmitri Lau (http://www.sitepoint.com/simple-animations-using-requestanimationframe/)
  3. jQuery's easing functions from https://github.com/danro/jquery-easing/blob/master/jquery.easing.js
  4. Robert Penners easing equations from http://robertpenner.com/easing/

How To Use

CDN

To Start An Animation

nAnimate.start([duration in milliseconds], [function to call with the % complete], [(optional) name of the easing function to use]);

For example:

nAnimate.start(1000, function(rate)
{
    // grow the div width from 100 to 300
    element.style.width = 100 + (rate * 200) + "px";
});

nAnimate.start(2000, function(rate)
{
    element.style.height = 100 + (rate * 200) + "px";
}, "easeInQuart");

To End An Animation

nAnimate.start will return an ID. Use the ID to cancel.

nAnimate.stop([ID]);

For example:

var ID = nAnimate.start(1000, function(rate)
{
    element.style.width = 100 + (rate * 200) + "px";
});

nAnimate.stop(ID);

To Get An Array Of The Available Easing Functions

nAnimate.easingFunctions();

For example:

var easingFunctions = nAnimate.easingFunctions();

Example

Check http://jsfiddle.net/imthenachoman/q1tdx8s4/ or the example.html file for an example and to see how each easing function looks.

nanimation's People

Contributors

imthenachoman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nanimation's Issues

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.