Coder Social home page Coder Social logo

mczolko / tinyanimate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from branneman/tinyanimate

0.0 2.0 0.0 48 KB

Animation micro library. Vanilla JavaScript.

Home Page: https://github.com/branneman/TinyAnimate

License: MIT License

JavaScript 53.58% HTML 46.42%

tinyanimate's Introduction

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.

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.

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.

tinyanimate's People

Contributors

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