Coder Social home page Coder Social logo

anim's Introduction

anim

Anim is a tiny and bare bones animation library weighing in at 7 KB in plain code, 2.8 KB when minified and 1.5 KB when gzipped.

Why Anim? Because sometimes if you only want a little animation, you may not want to pull in a full fledged library like jQuery which is 90 KB minified and 32 KB gzipped.

Anim can animate any property that accepts number and color values including but not limited to backgroundColor, opacity, width, scrollTop, etc.

demo

http://relay.github.com/anim_demo.html

features

  • Simple chaining syntax anim(---).anim(---).anim(---)
  • 3 easing functions
  • shorthand syntax anim("div1", {opacity: 0.6}, 2)

usage:

anim(node, properties, duration, ease*) or anim(delay) or anim(callbackFunction)

  • node: the node to animate, or the node's ID
  • properties: a map of CSS properties to animate (see below)
  • duration: time in seconds to run animation. e.g., 3.5 is 3.5 seconds
  • ease (optional): easing function name. Choose from "ease-in", "ease" (means: ease-in-out), "lin" (means: linear), and undefined means "ease-out". The individual easing properties will override this.
  • delay how long to wait before starting the next animation
  • callbackFunction function to call after animation finished

The properties object takes the form of:

{cssName: endValue} or {cssName: {to:endValue, fr:startValue*, e:easingFunction*, u:units*}}

  • cssName: the css property to animate; written in camelCase (margin-left --> marginLeft)
  • to: the end value of the CSS property. Can be number or string with optional units. e.g., 100, "100px", "50%", "3em"
  • fr (optional): the starting value of the CSS property. If not supplied, it is read from the node
  • e (optional): easing function name. (see above)
  • u (optional): unit of measurement. e.g., px, %, pt

This function returns an object with one method ("anim"), which allows you to start another animation after the first one is done. If that second function is called with one parameter, it is assumed to be a callback function and is called after the last animation is done.

examples:

anim(box, {opacity: {to: 0.2, fr: 1}},     2);  //long form specifying 'to' and 'from'
anim(box, {opacity: 0.2},                    2);
anim(box, {height:  300},                    2,    "ease-in");
anim(box, {height:  "14em",  width: "14em"}, 2);
anim(box, {marginLeft: "2%", fontSize: "20px"}, 2, "ease-out");
anim(document.body, {scrollTop: 500},   5,    "lin");

run 2 animations one after the other

anim(box, {height:300}, 2)
  .anim(box, {width:300}, 2)
  .anim(function() { alert("all done") });

run 2 animations with a 1 second delay in between

anim(box, {height:300}, 2)
  .anim(1)
  .anim(box, {width:300}, 2);

support:

Supports IE6+, Firefox 2+, Chrome, iOS, Android

If requestAnimationFrame is available it is used, which provides the highest frame rate and throttling if the CPU is busy or if another tab is focused.

anim's People

Contributors

relay-zz avatar

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.