Convert Figma logo to code with AI

bendc logoanimateplus

A+ animation module for the modern web

5,957
280
5,957
0

Top Related Projects

50,532

JavaScript animation engine

🍿 A cross-browser library of CSS animations. As easy to use as an easy thing.

20,011

GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web

18,496

The motion graphics toolbelt for the web

6,687

Tools for smoother shape animations.

15,273

JavaScript library to make drawing animation on SVG

Quick Overview

Animate Plus is a lightweight JavaScript animation library that allows developers to create smooth and performant animations with minimal code. It focuses on simplicity and efficiency, providing a straightforward API for animating CSS properties and transformations.

Pros

  • Lightweight and fast, with a small file size (around 2KB gzipped)
  • Simple and intuitive API, making it easy to create complex animations
  • Supports both CSS properties and transformations
  • Chainable methods for creating sequential animations

Cons

  • Limited built-in easing functions compared to some larger animation libraries
  • Lacks advanced features like timeline controls or complex path animations
  • May require more manual setup for complex, multi-element animations
  • Documentation could be more comprehensive for advanced use cases

Code Examples

Creating a simple fade-in animation:

animate({
  elements: ".fade-in",
  opacity: [0, 1],
  duration: 1000
});

Animating multiple properties with different durations:

animate({
  elements: "#box",
  translate: [0, 100],
  scale: [1, 1.5],
  duration: 1000
}).then({
  opacity: [1, 0],
  duration: 500
});

Creating a looping animation:

const pulse = animate({
  elements: ".pulse",
  scale: [1, 1.1],
  duration: 500,
  direction: "alternate",
  iterations: Infinity
});

Getting Started

  1. Include the Animate Plus library in your HTML file:
<script src="https://cdn.jsdelivr.net/npm/animateplus@2/animateplus.js"></script>
  1. Create an animation using the animate function:
animate({
  elements: ".my-element",
  translate: [0, 50],
  opacity: [0, 1],
  duration: 1000,
  easing: "out-cubic"
});
  1. Chain animations or add callbacks as needed:
animate({
  elements: "#box",
  scale: [1, 1.5]
}).then({
  rotate: 360
}).then(() => {
  console.log("Animation complete!");
});

Competitor Comparisons

50,532

JavaScript animation engine

Pros of Anime

  • More comprehensive feature set, including SVG animations and timeline control
  • Larger community and more frequent updates
  • Better documentation and examples

Cons of Anime

  • Larger file size (about 17KB minified)
  • Steeper learning curve due to more complex API
  • May be overkill for simple animations

Code Comparison

AnimatePlus:

animate({
  elements: '.box',
  duration: 1000,
  easing: 'ease-out',
  transform: ['translateX(0px)', 'translateX(100px)']
});

Anime:

anime({
  targets: '.box',
  translateX: 100,
  duration: 1000,
  easing: 'easeOutQuad'
});

Summary

AnimatePlus is a lightweight animation library focused on simplicity and performance. It's ideal for basic animations and projects where file size is a concern. Anime, on the other hand, offers a more robust set of features and better community support, making it suitable for complex animations and larger projects. The choice between the two depends on the specific requirements of your project and the level of animation complexity you need.

🍿 A cross-browser library of CSS animations. As easy to use as an easy thing.

Pros of Animate.css

  • Larger community and more widespread adoption
  • Extensive collection of pre-built animations
  • Easy to use with simple CSS classes

Cons of Animate.css

  • Larger file size, potentially impacting page load times
  • Less flexibility for custom animations
  • Requires including the entire library even if only a few animations are used

Code Comparison

Animate.css:

<h1 class="animate__animated animate__bounce">An animated element</h1>

AnimatePlus:

animate({
  elements: "h1",
  duration: 1000,
  transform: ["translateY(0px)", "translateY(-20px)"]
});

Key Differences

AnimatePlus is a JavaScript-based animation library, offering more programmatic control and customization. It allows for creating complex animations with less code and provides better performance for dynamic animations.

Animate.css, on the other hand, is a pure CSS animation library that's easier to implement for simple use cases but may be less flexible for complex or dynamic animations.

The choice between the two depends on the project requirements, desired level of control, and the developer's preference for working with CSS or JavaScript for animations.

20,011

GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web

Pros of GSAP

  • More comprehensive feature set, including complex animations and timeline control
  • Extensive documentation and community support
  • Cross-browser compatibility and performance optimization

Cons of GSAP

  • Larger file size and potential overhead for simpler projects
  • Steeper learning curve due to its extensive API
  • Commercial license required for some use cases

Code Comparison

GSAP:

gsap.to(".box", {duration: 2, x: 100, y: 50, rotation: 360});

Animateplus:

animate({
  elements: ".box",
  duration: 2000,
  transform: ["translateX(0)", "translateX(100px)"]
});

Key Differences

  • GSAP offers a more powerful and flexible animation system
  • Animateplus focuses on simplicity and lightweight implementation
  • GSAP provides better support for complex, multi-step animations
  • Animateplus has a smaller footprint and may be suitable for simpler projects

Use Cases

  • Choose GSAP for complex, professional-grade animations and interactive experiences
  • Opt for Animateplus when working on smaller projects with basic animation needs

Both libraries have their strengths, and the choice depends on project requirements, performance considerations, and developer preferences.

18,496

The motion graphics toolbelt for the web

Pros of mojs

  • More comprehensive and feature-rich animation library
  • Supports complex shape animations and custom easing functions
  • Larger community and more extensive documentation

Cons of mojs

  • Steeper learning curve due to its complexity
  • Larger file size, which may impact page load times
  • Requires more setup and configuration for basic animations

Code Comparison

mojs:

const burst = new mojs.Burst({
  radius:   { 0: 100 },
  count:    5,
  children: {
    shape:      'circle',
    fill:       { 'cyan' : 'yellow' },
    duration:   2000
  }
});

Animateplus:

animate({
  elements: ".circle",
  duration: 2000,
  transform: ["scale(0)", "scale(1)"],
  fill: ["cyan", "yellow"]
});

Summary

mojs is a more powerful and versatile animation library, offering advanced features and complex animations. However, it comes with a steeper learning curve and larger file size. Animateplus, on the other hand, provides a simpler API for basic animations, making it easier to use for beginners and lighter in terms of file size. The choice between the two depends on the project's requirements and the developer's familiarity with animation concepts.

6,687

Tools for smoother shape animations.

Pros of Flubber

  • Specializes in shape morphing and interpolation between SVG paths
  • Provides more advanced shape transformation capabilities
  • Offers better performance for complex shape animations

Cons of Flubber

  • Limited to SVG path animations, less versatile for general-purpose animations
  • Steeper learning curve due to its specialized nature
  • Requires more setup and configuration for basic animations

Code Comparison

Animateplus:

animate({
  elements: ".box",
  duration: 1000,
  easing: "out-cubic",
  transform: ["translateX(0px)", "translateX(200px)"]
});

Flubber:

const interpolator = flubber.interpolate(startPath, endPath);
d3.select("path")
  .transition()
  .duration(1000)
  .attrTween("d", () => interpolator);

Summary

Animateplus is a lightweight, general-purpose animation library suitable for various web animations. It offers a simple API and is easy to use for basic animations.

Flubber, on the other hand, excels in shape morphing and SVG path interpolation. It provides more advanced capabilities for complex shape transformations but has a narrower focus compared to Animateplus.

Choose Animateplus for general web animations and simpler projects. Opt for Flubber when working with complex SVG shape morphing and interpolation tasks.

15,273

JavaScript library to make drawing animation on SVG

Pros of Vivus

  • Specialized in SVG animation, particularly for drawing SVG paths
  • Offers multiple animation types (delayed, sync, oneByOne, scenario)
  • Provides a simple API for controlling animations (play, stop, reset)

Cons of Vivus

  • Limited to SVG animations only
  • Requires SVG elements to be present in the DOM
  • Less flexible for general-purpose animations compared to Animateplus

Code Comparison

Vivus:

new Vivus('my-svg', {duration: 200, type: 'delayed'}, myCallback);

Animateplus:

animate({
  elements: ".my-element",
  duration: 1000,
  easing: "out-elastic",
  transform: ["translateX(0)", "translateX(100px)"]
});

Key Differences

  • Vivus focuses on SVG path animations, while Animateplus is a more general-purpose animation library
  • Animateplus uses a more declarative approach with a single function call
  • Vivus requires SVG elements, whereas Animateplus can animate various CSS properties on any DOM element
  • Animateplus offers more built-in easing functions and supports custom easing
  • Vivus provides specific controls for SVG drawing animations, which Animateplus doesn't directly support

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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:

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

DefaultType
nullString | 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

DefaultType
out-elasticString

Determines the acceleration curve of your animation.

constantacceleratedecelerateaccelerate-decelerate
linearin-cubicout-cubicin-out-cubic
in-quarticout-quarticin-out-quartic
in-quinticout-quinticin-out-quintic
in-exponentialout-exponentialin-out-exponential
in-circularout-circularin-out-circular
in-elasticout-elasticin-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

DefaultType
1000Number | 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.

// 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

DefaultType
0Number | 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.

// 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

DefaultType
falseBoolean

Determines if the animation should repeat.

direction

DefaultType
normalString

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

speed

DefaultType
1Number

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

DefaultType
falseBoolean

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

DefaultType
nullObject | 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

DefaultType
nullFunction

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.

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

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

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.

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 <script type=module> in the following browsers:

  • Chrome 61
  • Safari 11.1
  • Firefox 60

Content delivery networks

Animate Plus is available on CDNJS and jsDelivr.

import animate from "https://cdn.jsdelivr.net/npm/animateplus@2/animateplus.js";

animate({
  elements: "div",
  transform: ["translate(0%)", 100]
});

Best practices

Animations play a major role in the design of good user interfaces. They help connecting actions to consequences, make the flow of interactions manifest, and greatly improve the polish and perception of a product. However, animations can be damaging and detrimental to the user experience if they get in the way. Here are a few best practices to keep your animations effective and enjoyable:

  • Speed: Keep your animations fast. A quick animation makes a software feel more productive and responsive. The optimal duration depends on the effect and animation curve, but in most cases you should likely stay under 500 milliseconds.
  • Easing: The animation curve contributes greatly to a well-crafted animation. The ease-out options are usually a safe bet as animations kick off promptly, making them react to user interactions instantaneously.
  • Performance: Having no animation is better than animations that stutter. When animating HTML elements, aim for using exclusively transform and opacity as these are the only properties browsers can animate cheaply.
  • Restraint: Tone down your animations and respect user preferences. Animations can rapidly feel overwhelming and cause motion sickness, so it's important to keep them subtle and to attenuate them even more for users who need reduced motion, for example by using matchMedia("(prefers-reduced-motion)") in JavaScript.

Examples

  • Stress test: 500 elements animated concurrently.
  • Burst: Intensive burst animation based on mousemove/touchmove.
  • Accordion: Animated accordion.
  • Morphing: CSS polygon morphing using clip-path.
  • Motion path: Animation along a custom path.
  • Line drawing: SVG line drawing animation.
  • Elasticity: SVG circles following your clicks.
  • External SVG: Animating paths from an external SVG file.
  • Anchors: Anchor scrolling animation using change().
  • Progress: Animation progress using change().
  • Text: Text splitting animation.

NPM DownloadsLast 30 Days