Top Related Projects
GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web
🍿 A cross-browser library of CSS animations. As easy to use as an easy thing.
JavaScript/TypeScript animation engine
The motion graphics toolbelt for the web
Javascript library to create physics-based animations
Quick Overview
Velocity.js is a lightweight JavaScript animation library that provides smooth and efficient animations for web applications. It aims to be faster and more feature-rich than jQuery's $.animate() while maintaining a similar API, making it easy for developers to transition from jQuery to Velocity.
Pros
- High performance: Velocity.js is optimized for speed and efficiency, often outperforming native CSS animations
- Feature-rich: Includes advanced features like scroll-based animations, color animations, and transforms
- jQuery-like syntax: Familiar API for developers transitioning from jQuery
- Standalone: Can be used without jQuery, reducing dependencies
Cons
- Learning curve: While similar to jQuery, some concepts and advanced features may require additional learning
- Limited browser support for older versions: Newer features may not work in older browsers
- Maintenance concerns: The project has seen less frequent updates in recent years
- File size: While relatively small, it may still add unnecessary weight for simple animations
Code Examples
- Basic animation:
Velocity(element, { opacity: 0.5, width: "300px" }, { duration: 1000 });
This code animates an element's opacity to 0.5 and width to 300px over 1 second.
- Chained animations:
Velocity(element, { height: "100px" })
.velocity({ width: "100px" })
.velocity({ opacity: 0 });
This code chain performs three consecutive animations: height, then width, then opacity.
- Scroll-based animation:
Velocity(element, "scroll", {
container: $("#container"),
offset: "-100px",
duration: 1000,
easing: "ease-in-out"
});
This code scrolls the element into view within a container, with an offset and custom easing.
Getting Started
- Include Velocity.js in your project:
<script src="https://cdnjs.cloudflare.com/ajax/libs/velocity/2.0.6/velocity.min.js"></script>
- Basic usage:
// Animate an element
Velocity(document.getElementById("myElement"), { opacity: 0, translateY: "200px" });
// With options
Velocity(document.querySelector(".target"), { scale: 1.5 }, { duration: 2000, easing: "ease-out" });
// Using selectors (requires Velocity UI pack)
Velocity("div", { backgroundColor: "#ff0000" }, { delay: 100 });
For more advanced usage and features, refer to the Velocity.js documentation.
Competitor Comparisons
GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web
Pros of GSAP
- More comprehensive feature set, including advanced timeline control and complex animations
- Better performance, especially for complex animations and on mobile devices
- Extensive plugin ecosystem for specialized effects and integrations
Cons of GSAP
- Steeper learning curve due to its extensive API and features
- Larger file size, which may impact load times for smaller projects
- Commercial license required for some use cases, unlike Velocity's MIT license
Code Comparison
GSAP:
gsap.to(".box", {duration: 1, x: 100, y: 50, rotation: 360});
Velocity:
Velocity(document.querySelector(".box"), {translateX: 100, translateY: 50, rotateZ: 360}, {duration: 1000});
Both libraries offer concise syntax for basic animations, but GSAP's API is generally more intuitive and flexible for complex scenarios. GSAP also provides a more consistent cross-browser experience, especially for 3D transforms and SVG animations.
While Velocity is lightweight and easy to use for simple animations, GSAP excels in handling complex, timeline-based animations and offers more advanced features like morphing and physics-based motion. However, Velocity may be preferable for projects with simpler animation needs or strict file size constraints.
🍿 A cross-browser library of CSS animations. As easy to use as an easy thing.
Pros of Animate.css
- Simpler to implement with pre-defined CSS classes
- Lightweight and easy to integrate into existing projects
- Extensive library of ready-to-use animations
Cons of Animate.css
- Less flexibility for custom animations
- Limited control over animation timing and sequencing
- Potential for overuse leading to performance issues
Code Comparison
Animate.css:
<div class="animate__animated animate__bounce">
This element will bounce
</div>
Velocity:
$("#element").velocity({
translateY: "50px",
opacity: 1
}, {
duration: 400,
easing: "easeOutQuad"
});
Key Differences
Animate.css is a CSS-based animation library that provides pre-defined classes for common animations. It's easy to use but offers less control over animation details. Velocity, on the other hand, is a JavaScript animation engine that provides more flexibility and performance optimization.
Animate.css is ideal for quick, simple animations, while Velocity is better suited for complex, custom animations with precise timing and sequencing. Velocity also offers better performance for animating large numbers of elements simultaneously.
Choose Animate.css for rapid prototyping and simple projects, and Velocity for more advanced animation requirements and performance-critical applications.
JavaScript/TypeScript animation engine
Pros of Tween.js
- Lightweight and focused solely on tweening, making it more suitable for projects that don't require a full animation library
- Supports a wider range of easing functions out of the box
- Better performance for simple tweening tasks due to its specialized nature
Cons of Tween.js
- Less feature-rich compared to Velocity, lacking advanced features like scroll-based animations
- Smaller community and ecosystem, potentially leading to fewer resources and third-party plugins
- May require additional libraries for more complex animation scenarios
Code Comparison
Velocity:
Velocity(element, { opacity: 0.5, width: "300px" }, { duration: 1000, easing: "easeInOutQuad" });
Tween.js:
new TWEEN.Tween({ opacity: 1, width: 200 })
.to({ opacity: 0.5, width: 300 }, 1000)
.easing(TWEEN.Easing.Quadratic.InOut)
.onUpdate(function(obj) {
element.style.opacity = obj.opacity;
element.style.width = obj.width + 'px';
})
.start();
Both libraries offer smooth animation capabilities, but Velocity provides a more concise API for DOM manipulation, while Tween.js offers more flexibility for custom property tweening.
The motion graphics toolbelt for the web
Pros of mojs
- More comprehensive animation toolkit with support for complex shape animations and custom effects
- Built-in timeline feature for sequencing and coordinating multiple animations
- Modular architecture allowing for smaller bundle sizes when using specific features
Cons of mojs
- Steeper learning curve due to its more extensive API and concepts
- Less widespread adoption and community support compared to Velocity
- Fewer pre-built easing functions out of the box
Code Comparison
mojs:
const burst = new mojs.Burst({
radius: { 0: 100 },
count: 5,
children: {
shape: 'circle',
fill: { 'cyan' : 'yellow' },
duration: 2000
}
});
Velocity:
$element.velocity({
width: "500px",
height: "500px"
}, {
duration: 2000,
easing: "easeInOutQuad"
});
mojs offers more advanced animation capabilities, allowing for complex shape animations and custom effects. It includes a built-in timeline feature for coordinating multiple animations, which Velocity lacks. However, mojs has a steeper learning curve and less community support. Velocity, on the other hand, is simpler to use and has better browser support, but is limited to DOM element animations. The code comparison shows mojs's ability to create complex shape animations, while Velocity focuses on simpler property animations for DOM elements.
Javascript library to create physics-based animations
Pros of dynamics.js
- Focuses on physics-based animations, offering more realistic and natural-looking motion
- Provides a simpler API with fewer options, making it easier to use for basic animations
- Smaller file size, which can be beneficial for projects with limited resources
Cons of dynamics.js
- Less feature-rich compared to Velocity, with fewer animation options and utilities
- Limited browser support, especially for older versions
- Lacks some of the advanced features found in Velocity, such as color animations and SVG support
Code Comparison
dynamics.js:
dynamics.animate(element, {
translateX: 100,
scale: 2
}, {
type: dynamics.spring,
duration: 1000
});
Velocity:
Velocity(element, {
translateX: 100,
scale: 2
}, {
easing: "spring",
duration: 1000
});
Both libraries offer similar syntax for basic animations, but Velocity provides more options for customization and advanced features. dynamics.js focuses on physics-based animations, while Velocity offers a wider range of easing functions and animation types. The choice between the two depends on the specific needs of the project, with dynamics.js being more suitable for simpler, physics-based animations, and Velocity offering more versatility for complex animation requirements.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
# Velocity beta
NPM: npm install velocity-animate@beta
Docs
https://github.com/julianshapiro/velocity/wiki
IMPORTANT: The velocityjs.org documentation refers to V1, not V2 beta - use the wiki for latest documentation!
News
WhatsApp, Tumblr, Windows, Samsung, Uber, and thousands of other companies rely on Velocity. Visit Libscore.com to see which sites use Velocity on their homepage.
React Plugin
Announcement: https://fabric.io/blog/introducing-the-velocityreact-library
Repo: https://github.com/twitter-fabric/velocity-react
NPM: https://www.npmjs.com/package/velocity-react
Quickstart
Velocity (CDN, choose one of them):
<script src="//cdn.jsdelivr.net/npm/velocity-animate@2.0/velocity.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/velocity/2.0.6/velocity.min.js"></script>
Velocity UI pack (CDN, choose one of them):
<script src="//cdn.jsdelivr.net/npm/velocity-animate@2.0/velocity.ui.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/velocity/2.0.6/velocity.ui.min.js"></script>
Please note that JSDelivr can automatically supply the latest release, while CloudFlare needs to ask for a specific version.
Package managers:
npm: npm install velocity-animate@beta
Automagic chaining:
If using the .velocity(...)
chained function in libraries such as jQuery or Zepto you need to ensure that Velocity is loaded after them. If you wish to add it to anything loaded afterwards then look at the Velocity.patch() method.
Questions or Problems?
Ask on StackOverflow (make sure you add the [velocity.js]
and the [javascript]
or [typescript]
tags).
Updates
- 2.0: Typescript update and complete refactoring.
- 1.5: Bugfixes, IE9 compatibility fixes.
- 1.4: Pause / Resume (per element or global).
Forcefed string animation (just have matching number spaces) including unit conversions and colour names (iebackground:["rgba(red,0.1)", "blue"]
). High resolution timers (animations should be slightly smoother).
Various fixes including ticker (loading Velocity in a background window) and color handling. - 1.3: Code cleanup - no breaking changes known.
- 1.2: Custom tweens. Custom easings. "Finish" command.
- 1.0: File name changed to
velocity.js
. Read VelocityJS.org/#dependencies. - 0.1:
stop
now stops animations immediately (instead of only clearing the remainder of the animation queue). No other backwards-incompatible changes were made.
Learn
- Motion design: smashingmagazine.com/2014/06/18/faster-ui-animations-with-velocity-js
- Animating without jQuery: smashingmagazine.com/2014/09/04/animating-without-jquery
- Performance comparisons: davidwalsh.name/css-js-animation
- Workflow: css-tricks.com/improving-ui-animation-workflow-velocity-js
Comparisons
- CSS transitions are meant for simple interface flourishes.
- jQuery's $.animate() is slow and poorly-equipped for motion design.
- Velocity is a fast, feature-rich standalone alternative to jQuery's $.animate().
License
MIT License. © Julian Shapiro (http://twitter.com/julian).
Sponsors
Top Related Projects
GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web
🍿 A cross-browser library of CSS animations. As easy to use as an easy thing.
JavaScript/TypeScript animation engine
The motion graphics toolbelt for the web
Javascript library to create physics-based animations
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot