• Stars
    star
    108
  • Rank 321,259 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Animation micro library. Vanilla JavaScript.

TinyAnimate

Animation micro library. Vanilla JavaScript, includes a global and UMD. Minified to only 3.8kb. Uses requestAnimationFrame() if available, falls back to setTimeout().

Supports all the easings you can find on easings.net, and custom easing functions.

Download ZIP | npm version

Examples

Animating a CSS style:

var square = document.querySelector('.square');
TinyAnimate.animateCSS(square, 'marginLeft', 'px', 10, 70, 500, 'easeInOutQuart', function() {
    console.log('done!!!111oneone');
});

Animating the 'x' property on an SVG element:

var square = document.querySelector('.square');
TinyAnimate.animate(70, 10, 1000, function(x) {
    square.setAttribute('x', x);
});

Using Require.js, changing the opacity of a rgba color:

define(['TinyAnimate'], function(TinyAnimate) {
    var elem = document.querySelector('button.send');
    elem.addEventListener('click', function(e) {
        TinyAnimate.animate(1, .5, 500, function(opacity) {
            square.style.backgroundColor = 'rgba(65, 131, 196, ' + opacity + ')';
        });
    });
});

Usage

Interface

  1. TinyAnimate.animate(from, to, duration, update, easing, done)
    • from (int) โ€” Property value to animate from
    • to (int) โ€” Property value to animate to
    • duration (int) โ€” Duration in milliseconds
    • update (function) โ€” Function to implement updating the DOM, get's called with a value between from and to
    • easing (string | function) โ€” Optional: A string when the easing function is available in TinyAnimate.easings, or a function with the signature: function(t, b, c, d) {...}
    • done (function) โ€” Optional: To be executed when the animation has completed.
  2. TinyAnimate.animateCSS(element, property, unit, from, to, duration, easing, done)
    • element (HTMLElement) โ€” A dom node
    • property (string) โ€” Property name, as available in element.style, i.e. 'borderRadius', not 'border-radius'
    • unit (string) โ€” Property unit, like 'px'
    • from (int) โ€” Property value to animate from
    • to (int) โ€” Property value to animate to
    • duration (int) โ€” Duration in milliseconds
    • easing (string | function) โ€” Optional: A string when the easing function is available in TinyAnimate.easings, or a function with the signature: function(t, b, c, d) {...}
    • done (function) โ€” Optional: To be executed when the animation has completed.
  3. TinyAnimate.cancel(animation)
    • animation (object) - Animation object returned from animate or animateCSS.

Easings

All the easings found at easings.net are supported. I suggest you strip out all the easings you do not use in production to keep the bytes down. If you don't specify an easing, or specify an incorrect easing, the default linear easing will be used.

It's also possible to specify the easing as a function. Read more about creating easing functions manually here and here.

requestAnimationFrame

It uses the unprefixed version of requestAnimationFrame, if available. You can however include a polyfill as well, if you need to support more browsers. See caniuse.com/requestanimationframe for more detailed browser support, everthing that needs a prefix will only use requestAnimationFrame whenever a polyfill has been included. If window.requestAnimationFrame is not found, setTimeout() will be used.

A polyfill for requestAnimationFrame is included in the project, but you are not required to use it. Choose wisely.

License

Released under the MIT license.

More Repositories

1

current-processes

Node.js library to get a snapshot of the currently running processes, OS-agnostic
JavaScript
97
star
2

dotfiles

Shell
36
star
3

nodejs-app-boilerplate

A Node.js server-side app boilerplate with HTTP/2 server push and Critical CSS
JavaScript
12
star
4

SpeedyImages

SpeedyImages is a command line image optimization tool written in Python. It optimizes by running the image through several tools.
Python
5
star
5

frntndr

An opinionated blueprint environment to quick start new front-end codebases
JavaScript
4
star
6

resize-browser-window-bookmarklet

A bookmarklet which can resize your browser window to any of the common resolutions. It currently has all the common desktop, Android (both tablet and mobile) and iOS screen sizes.
JavaScript
4
star
7

included-fonts-by-software

2
star
8

fp.js

JavaScript
2
star
9

jsgrep-cli

An alternative to grep which uses JavaScript's Regex, supports a match and a match-and-replace
JavaScript
2
star
10

css-js-module-states

CSS-driven JavaScript state changer
JavaScript
2
star
11

recipe-manager-6k

CSS
1
star
12

automated-functional-testing-bootstrap

JavaScript
1
star
13

lengthenizr-bookmarklet

JavaScript
1
star
14

middlewarejs

Ultra minimalistic expressjs-style middleware pattern implementation
JavaScript
1
star
15

scrumboard

A simple scrumboard application, implemented in React
JavaScript
1
star
16

HipsterTweetWall

Yet another tweet wall! What can I say. This one is quite minimalistic, only front-end. There's a Github hosted and self-hosted version available. It was created by Bran van der Meer so Fronteers 2012 would not have a Flash-based tweetwall, but a CSS3 animation-based one.
1
star