Velocity.js Animation Library

1.5.2 · active · verified Sun Apr 19

Velocity.js is a high-performance JavaScript animation library that provides a feature-rich and fast alternative to traditional methods like jQuery's `$.animate()` or basic CSS transitions. It enables complex UI motion design by optimizing DOM interactions to minimize layout thrashing and leveraging efficient JavaScript animation techniques. Key features include support for color animations, CSS transforms, loops, easings, SVG properties, and scrolling. Velocity.js offers an API that closely mirrors jQuery's `$.animate()`, allowing for seamless integration with or independent use from jQuery. The library is currently stable at version 2.0.6, released in September 2023, demonstrating ongoing maintenance and development. This version integrated the former `UI-Pack` animations directly into its core and introduced a Promise-based API for modern asynchronous control flow. It aims to deliver significantly smoother animations, especially on mobile devices, by focusing on performance at its core.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates animating a DOM element using Velocity.js ES module import. It shows basic property animation, chaining with Promises, custom easing, looping, and parallel animations.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Velocity.js Quickstart</title>
    <style>
        #myElement {
            width: 100px;
            height: 100px;
            background-color: steelblue;
            position: absolute;
            top: 50px;
            left: 50px;
            border-radius: 5px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-family: sans-serif;
            font-size: 1.2em;
        }
    </style>
</head>
<body>
    <div id="myElement">Animate Me</div>

    <script type="module">
        import Velocity from 'velocity-animate';

        const element = document.getElementById('myElement');

        Velocity(element, {
            translateX: '200px',
            rotateZ: '360deg',
            backgroundColor: '#ef5350'
        }, {
            duration: 1500,
            easing: 'ease-in-out',
            loop: 2,
            delay: 500,
            complete: () => {
                console.log('Animation complete!');
                // Chain another animation using Promises (V2 feature)
                Velocity(element, {
                    scale: 0.8,
                    opacity: 0.5
                }, {
                    duration: 800,
                    easing: [250, 15] // Custom bezier easing
                }).then(() => {
                    console.log('Second animation complete!');
                    element.textContent = 'Done!';
                });
            }
        });

        // Example of animating another element concurrently
        const anotherElement = document.createElement('div');
        anotherElement.id = 'anotherElement';
        anotherElement.style.cssText = `
            width: 80px; height: 80px; background-color: goldenrod;
            position: absolute; top: 200px; left: 50px; border-radius: 50%;
            display: flex; align-items: center; justify-content: center;
            color: white; font-size: 0.9em;
        `;
        anotherElement.textContent = 'Hello';
        document.body.appendChild(anotherElement);

        Velocity(anotherElement, {
            left: '300px',
            top: '250px',
            backgroundColor: 'purple'
        }, {
            duration: 1000,
            delay: 1000,
            begin: () => console.log('Starting second element animation')
        });
    </script>
</body>
</html>

view raw JSON →