Animate Plus is a JavaScript animation library focusing on performance and authoring flexibility

Overview

Animate Plus

Animate Plus is a JavaScript animation library focusing on performance and authoring flexibility. It aims to deliver a steady 60 FPS and weighs less than 3 KB (minified and compressed), making it particularly well-suited for mobile.

Getting started

npm install animateplus or download animateplus.js and start animating things:

index * 100, transform: ["scale(0)", "scale(1)"] }) .then(options => animate({ ...options, transform: ["translate(0%)", "translate(500%)"] }));">
import animate from "/animateplus.js";

animate({
  elements: "div",
  duration: 2000,
  delay: index => index * 100,
  transform: ["scale(0)", "scale(1)"]
})
.then(options => animate({
  ...options,
  transform: ["translate(0%)", "translate(500%)"]
}));

Preview this example →

Options

elements

Default Type
null String | Element | NodeList | Array

Determines the DOM elements to animate. You can either pass it a CSS selector or DOM elements.

animate({
  elements: document.body.children,
  transform: ["rotate(0turn)", "rotate(1turn)"]
});

easing

Default Type
out-elastic String

Determines the acceleration curve of your animation.

constant accelerate decelerate accelerate-decelerate
linear in-cubic out-cubic in-out-cubic
in-quartic out-quartic in-out-quartic
in-quintic out-quintic in-out-quintic
in-exponential out-exponential in-out-exponential
in-circular out-circular in-out-circular
in-elastic out-elastic in-out-elastic

The amplitude and period of elastic easings can be configured by providing space-separated values. Amplitude defaults to 1, period to 0.4.

// Increase elasticity
animate({
  elements: "span",
  easing: "out-elastic 1.4 0.2",
  transform: ["translate(0px)", "translate(500px)"]
});

duration

Default Type
1000 Number | Function

Determines the duration of your animation in milliseconds. By passing it a callback, you can define a different duration for each element. The callback takes the index of each element as its argument and returns a number.

(index + 1) * 1000, opacity: [1, 0] });">
// First element fades out in 1s, second element in 2s, etc.
animate({
  elements: "span",
  easing: "linear",
  duration: index => (index + 1) * 1000,
  opacity: [1, 0]
});

delay

Default Type
0 Number | Function

Determines the delay of your animation in milliseconds. By passing it a callback, you can define a different delay for each element. The callback takes the index of each element as its argument and returns a number.

(index + 1) * 1000, opacity: [1, 0] });">
// First element fades out after 1s, second element after 2s, etc.
animate({
  elements: "span",
  easing: "linear",
  delay: index => (index + 1) * 1000,
  opacity: [1, 0]
});

loop

Default Type
false Boolean

Determines if the animation should repeat.

direction

Default Type
normal String

Determines the direction of the animation. reverse runs the animation backwards, alternate switches direction after each iteration if the animation loops.

speed

Default Type
1 Number

Determines the animation playback rate. Useful in the authoring process to speed up some parts of a long sequence (value above 1) or slow down a specific animation to observe it (value below 1).

optimize

Default Type
false Boolean

Forces hardware acceleration during an animation if set to true. Unless you experience performance issues, it's recommended to leave it off as hardware acceleration comes with potentially harmful side-effects.

blur

Default Type
null Object | Function

Simulates a motion blur effect. Takes an object or a function returning an object that specifies the strength of the directional blur on the x and y axes. A missing axis defaults to 0, which disables the blur on that axis.

animate({
  elements: "circle",
  easing: "out-exponential",
  duration: 2500,
  loop: true,
  direction: "alternate",
  blur: {x: 20, y: 2},
  transform: ["translate(0%)", "translate(80%)"]
});

Preview this example →

change

Default Type
null Function

Defines a callback invoked on every frame of the animation. The callback takes as its argument the animation progress (between 0 and 1) and can be used on its own without being tied to elements.

document.body.textContent = `${Math.round(progress * 100)}%` });">
// Linearly outputs the percentage increase during 5s
animate({
  duration: 5000,
  easing: "linear",
  change: progress =>
    document.body.textContent = `${Math.round(progress * 100)}%`
});

Animations

Animate Plus lets you animate HTML and SVG elements with any property that takes numeric values, including hexadecimal colors.

// Animate the radius and fill color of an SVG circle
animate({
  elements: "circle",
  r: [0, 50],
  fill: ["#80f", "#fc0"]
});

Each property you animate needs an array defining the start and end values. For convenience, you can omit everything but the numbers in the end values.

// Same as ["translate(0px)", "translate(100px)"]
animate({
  elements: "span",
  transform: ["translate(0px)", 100]
});

These arrays can optionally be returned by a callback that takes the index of each element, just like with duration and delay.

["translate(0px)", (index + 1) * 100] });">
// First element translates by 100px, second element by 200px, etc.
animate({
  elements: "span",
  transform: index => ["translate(0px)", (index + 1) * 100]
});

Promise

animate() returns a promise which resolves once the animation finishes. The promise resolves to the object initially passed to animate(), making animation chaining straightforward and convenient. The Getting started section gives you a basic promise example.

Since Animate Plus relies on native promises, you can benefit from all the usual features promises provide, such as Promise.all, Promise.race, and especially async/await which makes animation timelines easy to set up.

const play = async () => {
  const options = await animate({
    elements: "span",
    duration: 3000,
    transform: ["translateY(-100vh)", 0]
  });

  await animate({
    ...options,
    transform: ["rotate(0turn)", 1]
  });

  await animate({
    ...options,
    duration: 800,
    easing: "in-quintic",
    transform: ["scale(1)", 0]
  });
};

play();

Preview this example →

Additional functions

stop

Stops the animations on the elements passed as the argument.

8000 + index * 200, loop: true, transform: ["rotate(0deg)", 360] }); document.addEventListener("click", ({target}) => stop(target));">
import {stop} from "/animateplus.js";

animate({
  elements: "span",
  easing: "linear",
  duration: index => 8000 + index * 200,
  loop: true,
  transform: ["rotate(0deg)", 360]
});

document.addEventListener("click", ({target}) => stop(target));

Preview this example →

delay

Sets a timer in milliseconds. It differentiates from setTimeout() by returning a promise and being more accurate, consistent and battery-friendly. The delay option relies internally on this method.

console.log(`${time}ms elapsed`));">
import {delay} from "/animateplus.js";

delay(500).then(time => console.log(`${time}ms elapsed`));

Browser support

Animate Plus is provided as a native ES2015 module, which means you may need to transpile it depending on your browser support policy. The library works as is using

Comments
  • Clarify browser support

    Clarify browser support

    Hi,

    Wondering if it would be possible to clarify the current browser support in the README? E.g. adding a "Browser Support" section at the end.

    Cool project btw, thanks for sharing!

    opened by fvsch 6
  • Invalid value for path d errors in Chrome and Safari

    Invalid value for path d errors in Chrome and Safari

    Hi, @bendc! I ran into a quirk using this (otherwise awesome) library, I'm not sure how to troubleshoot further and figured it might be time to create an issue for it.

    I have an SVG illustration of my face (my avatar, actually), and I'm animating its d attribute so that one of the eyes morphs from an open eye to a closed eye.

    I can get the animation working using SMIL in Chrome, Firefox and Safari just fine. When I try to do the same animation using animateplus, it works great, but Chrome and Safari report console errors when the animation completes.

    Error in Chrome:

    animate.min.js:17
    Error: Invalid value for <path> attribute d="M103.5,82.4c0,2-3.8,3.9-7.6,3.7c-4.6-0.2-6.4-2-6.4-4.1c0-1.6,1.62.3,72.3C100.3,84.3,103.5,81.3,103.5,82.4z"
    

    Error in Safari:

    animate.min.js:17
    Error: Problem parsing d="M103.5,82.4c0,2-3.8,3.9-7.6,3.7c-4.6-0.2-6.4-2-6.4-4.1c0-1.6,1.62.3,72.3C100.3,84.3,103.5,81.3,103.5,82.4z"
    

    You can reproduce the problem in this pen I've created: http://codepen.io/tylersticka/pen/b2f6b448692ed74d9d6565ea49ff6849

    My first instinct was that my coordinates must not match up... maybe there are odd numbers or something. But I created the second by duplicating the first shape and moving its points around, and a visual inspection of the d attribute seems to support that the points are equal.

    So otherwise, I'm stumped! In order of likelihood, I imagine the problem might be...

    1. I did something stupid that you'll identify.
    2. Blink and Webkit are doing something stupid.
    3. There's a legitimate issue with the library.

    Thanks in advance for your help! :grimacing:

    opened by tylersticka 6
  • Animate SVG path d attribute

    Animate SVG path d attribute

    Animate Plus lets you animate HTML and SVG elements with any property that takes numeric values, including hexadecimal colors.

    I assume this library can't be used to animate paths like the following?

            <path id="path" d="M0 0 L 300 0 L 300 300.4 L 0 300 Z" fill="#ccc"></path>
    

    Unlike TweenLite or Anime.js? https://jsfiddle.net/alvarotrigo/6yev2wc0/18/

    
    $('button').click(function() {
        
        TweenLite.to('#path', 1, {
            attr:{d: 'M0 100 L 300 0 L 300 300.4 L 0 300 Z'}
        });
        
        TweenLite.to('#path', 1, {
            attr:{d: 'M50 50 L 300 0 L 300 300.4 L 0 300 Z'}
        }).delay(0.3);
    
       
    });
    
    opened by alvarotrigo 5
  • Cannot call JS method at the end of animation

    Cannot call JS method at the end of animation

    I want to call the JS method after the animation is finished. It seems that this operation is not supported now, only simple operation can be performed. Can you answer it? Thank you.

    opened by dumplingbao 3
  • Issue with IE/Edge

    Issue with IE/Edge

    I am using this library with vue-cli and got a problem running on IE/Edge. To fix that, I had to transpile with Babel and import the transpilled version instead of the package version. Basically, what I've done was that:

    babel transform-object-rest-spread node_modules/animateplus/animateplus.js --out-file animate.js
    

    and on import part:

    import animate from "./animate.js"
    
    opened by murilobd 3
  • Getting started example not working properly on chrome

    Getting started example not working properly on chrome

    The example at http://animateplus.com/examples/getting-started/ is not working properly on chrome. It's working fine on safari mobile and on firefox desktop.

    The animation on chrome scales the first box, but the last two don't animate the entrance, they just appear after the delay out of nowhere. Then the translate animation does work properly.

    opened by aecorredor 3
  • Example Repo

    Example Repo

    Hi @bendc, thank you for creating this library! Your examples were super inspiring, and I was wondering if there was a way to look at the code to help understand how the library works?

    opened by oyeanuj 3
  • Cannot call function as a class

    Cannot call function as a class

    Hi there!

    I'm very excited to try this out, but I've been trying to import the library in my react project and I cannot get it working unfortunately.

    I keep getting the error TypeError: Cannot call a class as a function.

    I'm importing as : import animate from 'lib/animateplus'

    Any help would be much appreciated!

    Best

    opened by aulneau 3
  • async/await not supported by preact-cli

    async/await not supported by preact-cli

    Hey Benjamin, first of all thx for this great + to my tool-lib. ;-) As with all of my chosen libs I really appreciate the small footprint and ease of use. I really would stick with it.

    To my problem: For my webdev I'm working with preact-cli which is currently not supporting async/await, unfortunately see #17 there. As I understand, this is because the overhead of runtime-transform is too high.

    As I dive in animateplus.js I see exactly 1 x async 1 x await

    Do you think it is possible to replace these with promise-then (not for your release, just for my preact-problem). Or hopefully you can just give me a hint on how to accomplish it. I'm really new to async/await-promises, so I didn't get it working until now by myself.

    I totally understand if you say: 'not my biz', but I hope you can give me a push in the right direction. Or you say 'forget it Dude, no way to get this working'.

    ++++ for animate+ thx again

    opened by vedam 3
  • Returning a Promise

    Returning a Promise

    Hi,

    first thank you first this jewel, really a saviour!

    Could you consider returning a Promise from animate call?

    Would solve https://github.com/bendc/animateplus/issues/6 and allow use of future async / await out of the box.

    opened by JSteunou 3
  • Map in animate.min.js

    Map in animate.min.js

    How do you compile animate.min.js? It looks like it is compiling some ES6 stuff like const, but not Map, which is causing some sad browsers to be sad.

    opened by forresto 3
Owner
Benjamin De Cock
I design and develop user interfaces.
Benjamin De Cock
simple JavaScript library to animate texts

Animated Texts Hi, this library is a simple javascript text animator Properties force type: number default: 300 start_delay_time type: number default:

Cristóvão 4 Jan 11, 2022
Lightweight, simple to use jQuery plugin to animate SVG paths

jQuery DrawSVG This plugin uses the jQuery built-in animation engine to transition the stroke on every <path> inside the selected <svg> element, using

Leonardo Santos 762 Dec 20, 2022
🐿 Super easy and lightweight(<3kb) JavaScript animation library

Overview AniX - A super easy and lightweight javascript animation library. AniX is a lightweight and easy-to-use animation library with excellent perf

anonymous namespace 256 Sep 19, 2022
GreenSock's GSAP JavaScript animation library (including Draggable).

GSAP (GreenSock Animation Platform) Professional-grade animation for the modern web GSAP is a robust JavaScript toolset that turns developers into ani

GreenSock 15.5k Jan 8, 2023
GreenSock's GSAP JavaScript animation library (including Draggable).

GSAP (GreenSock Animation Platform) Professional-grade animation for the modern web GSAP is a robust JavaScript toolset that turns developers into ani

GreenSock 15.4k Jan 5, 2023
Animation library that mimics CSS keyframes when scrolling.

Why Motus ? Motus allows developers to create beatuful animations that simulate css keyframes and are applied when the user scrolls. Features Node & B

Alexandru Cambose 580 Dec 30, 2022
Theatre.js is an animation library for high-fidelity motion graphics.

Theatre.js is an animation library for high-fidelity motion graphics. It is designed to help you express detailed animation, enabling you to create intricate movement, and convey nuance.

Aria 8.6k Jan 3, 2023
JavaScript animation engine

anime.js JavaScript animation engine | animejs.com Anime.js (/ˈæn.ə.meɪ/) is a lightweight JavaScript animation library with a simple, yet powerful AP

Julian Garnier 44k Dec 30, 2022
Accelerated JavaScript animation.

Velocity beta NPM: npm install velocity-animate@beta Docs https://github.com/julianshapiro/velocity/wiki IMPORTANT: The velocityjs.org documentation r

Julian Shapiro 17.2k Jan 5, 2023
CSS3 backed JavaScript animation framework

Move.js CSS3 JavaScript animation framework. About Move.js is a small JavaScript library making CSS3 backed animation extremely simple and elegant. Be

Sloth 4.7k Dec 30, 2022
Pure CSS (no JavaScript) implementation of Android Material design "ripple" animation

Pure CSS (no JavaScript) implementation of Android Material design "ripple" animation

Mladen Plavsic 334 Dec 11, 2022
Create scroll-based animation without JavaScript

Trigger JS Create scroll-based animation without JavaScript. Sometimes we want to update the CSS style of an HTML element based on the scroll position

Trigger JS 1.1k Jan 4, 2023
React particles animation background component

particles-bg React component for particles backgrounds This project refers to the source code of the Proton official website, I packaged it into a com

lindelof 561 Dec 24, 2022
Making Animation Simple

Just Animate 2 Making Animation Simple Main Features Animate a group of things as easily as a single thing Staggering and delays Chainable sequencing

Just Animate 255 Dec 5, 2022
Responsive, interactive and more accessible HTML5 canvas elements. Scrawl-canvas is a JavaScript library designed to make using the HTML5 canvas element a bit easier, and a bit more fun!

Scrawl-canvas Library Version: 8.5.2 - 11 Mar 2021 Scrawl-canvas website: scrawl-v8.rikweb.org.uk. Do you want to contribute? I've been developing thi

Rik Roots 227 Dec 31, 2022
Javascript and SVG odometer effect library with motion blur

SVG library for transitioning numbers with motion blur JavaScript odometer or slot machine effect library for smoothly transitioning numbers with moti

Mike Skowronek 793 Dec 27, 2022
Slickscroll - A Lightweight JavaScript library for quick and painless momentum & parallax scrolling effects.

Slickscroll is a JavaScript library that makes momentum & parallax scrolling quick and painless View Demo: slickscroll.musabhassan.com Momentum Scroll

Musab Hassan 33 Dec 28, 2022
A lightweight JavaScript library for creating particles

particles.js A lightweight JavaScript library for creating particles. Demo / Generator Configure, export, and share your particles.js configuration on

Vincent Garreau 26.7k Jan 8, 2023
Javascript library to create physics-based animations

Dynamics.js Dynamics.js is a JavaScript library to create physics-based animations To see some demos, check out dynamicsjs.com. Usage Download: GitHub

Michael Villar 7.5k Jan 6, 2023