Exciting news!Announcing our $4.6M Series Seed. Learn more
Socket
LoveBlogFAQ
Install
Log in

easing-animation-frames

Package Overview
Dependencies
1
Maintainers
1
Versions
16
Issues
File Explorer

Advanced tools

easing-animation-frames

Lightweight library for creating animation

    1.0.5latest

Version published
Maintainers
1
Yearly downloads
10,594
increased by338.13%

Weekly downloads

Readme

Source

Easing Animation Frames

test npm version Bundle size

npm i easing-animation-frames

This is a tiny library for creating CPU-friendly easing animations with requestAnimationFrame API and Robert Penner's easing equations. Suggestions and pull requests for optimization are welcome.

Bar Animation

How to use

Select an easing type (cubicInOut by default) and pass a callback function to run for every animation frame which manipulates target DOM elements.

Minimum settings

// Template function const updateBarWidth = ({ progress }) => { // Update the DOM with the progress value } easingAnimationFrames({ template: updateBarWidth // Callback function to run for every frame, which receives progress from 0 to 1 });

With optional settings

// Template function const updateBarWidth = ({ progress, stopFrames, // Stops the animation resumeFrames, // Resumes the animation restartFrames, // Restarts the animation }) => { // Update the DOM with the progress value } easingAnimationFrames({ easingType: "quadInOut", // Easing function name duration: 3000, // Animation duration in milliseconds template: updateBarWidth, // Callback function to run for every frame, which receives progress from 0 to 1 complete: animationComplete, // Callback funciton to run on completion });

Duration is set to be 4,000 milliseconds by default, which you can change. Once the animation starts, the callback function (template) receives the progress value (from 0 to 1) that you can use to render the animation. The example above uses (progress * 75)% for the width of the bar, based on the time passed.

The template function also provides stop and resume functions, if you want to stop the animation before it completes and resume it.

Browser Support

It uses requestAnimationFrame, which should be supported for most of the modern browsers.

Keywords

Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc