High-performance JavaScript animation library with TypeScript support providing DOM animations, transforms, UI effects, and comprehensive easing functions.
—
Velocity provides a comprehensive library of easing functions for natural motion, including CSS standard easings, mathematical curves, and physics-based easings.
interface BasicEasings {
linear: VelocityEasingFn;
swing: VelocityEasingFn;
spring: VelocityEasingFn;
}Constant rate of change with no acceleration or deceleration.
Default easing with gentle acceleration and deceleration (similar to ease-in-out).
Physics-based spring motion with natural bounce characteristics.
interface CSSEasings {
ease: VelocityEasingFn;
"ease-in": VelocityEasingFn;
"ease-out": VelocityEasingFn;
"ease-in-out": VelocityEasingFn;
}CSS standard easing (equivalent to cubic-bezier(0.25, 0.1, 0.25, 1)).
Slow start, fast finish (equivalent to cubic-bezier(0.42, 0, 1, 1)).
Fast start, slow finish (equivalent to cubic-bezier(0, 0, 0.58, 1)).
Slow start and finish, fast middle (equivalent to cubic-bezier(0.42, 0, 0.58, 1)).
interface SineEasings {
easeInSine: VelocityEasingFn;
easeOutSine: VelocityEasingFn;
easeInOutSine: VelocityEasingFn;
}Sine wave-based easings providing smooth, gentle curves.
interface QuadraticEasings {
easeInQuad: VelocityEasingFn;
easeOutQuad: VelocityEasingFn;
easeInOutQuad: VelocityEasingFn;
}Quadratic (power of 2) acceleration curves.
interface CubicEasings {
easeInCubic: VelocityEasingFn;
easeOutCubic: VelocityEasingFn;
easeInOutCubic: VelocityEasingFn;
}Cubic (power of 3) acceleration curves with more pronounced effects than quadratic.
interface QuarticEasings {
easeInQuart: VelocityEasingFn;
easeOutQuart: VelocityEasingFn;
easeInOutQuart: VelocityEasingFn;
}Quartic (power of 4) acceleration curves with strong acceleration effects.
interface QuinticEasings {
easeInQuint: VelocityEasingFn;
easeOutQuint: VelocityEasingFn;
easeInOutQuint: VelocityEasingFn;
}Quintic (power of 5) acceleration curves with very strong acceleration effects.
interface ExponentialEasings {
easeInExpo: VelocityEasingFn;
easeOutExpo: VelocityEasingFn;
easeInOutExpo: VelocityEasingFn;
}Exponential curves providing sharp acceleration changes.
interface CircularEasings {
easeInCirc: VelocityEasingFn;
easeOutCirc: VelocityEasingFn;
easeInOutCirc: VelocityEasingFn;
}Circular curves based on quarter-circle arcs.
interface BackEasings {
easeInBack: VelocityEasingFn;
easeOutBack: VelocityEasingFn;
easeInOutBack: VelocityEasingFn;
}Back easings that overshoot the target before settling, creating a "pull-back" effect.
interface ElasticEasings {
easeInElastic: VelocityEasingFn;
easeOutElastic: VelocityEasingFn;
easeInOutElastic: VelocityEasingFn;
}Elastic easings that oscillate around the target like a rubber band.
interface BounceEasings {
easeInBounce: VelocityEasingFn;
easeOutBounce: VelocityEasingFn;
easeInOutBounce: VelocityEasingFn;
}Bounce easings that simulate a bouncing ball effect.
interface StepEasings {
"at-start": VelocityEasingFn;
"at-end": VelocityEasingFn;
during: VelocityEasingFn;
}Step-based easings for discrete value changes.
function generateBezier(
x1: number,
y1: number,
x2: number,
y2: number
): VelocityEasingFn;Creates custom cubic-bezier easing functions.
interface SpringEasing {
(tension: number, friction: number): VelocityEasingFn;
}Physics-based spring easings with configurable tension and friction parameters.
type VelocityEasingType =
| VelocityEasingFn
| keyof VelocityEasings
| [number, number, number, number] // cubic-bezier values
| string;
type VelocityEasingFn = (
percentComplete: number,
startValue: number,
endValue: number,
duration: number
) => number;import Velocity from "velocity-animate";
// Use predefined easing
Velocity(element, { translateX: "200px" }, {
duration: 1000,
easing: "easeInOutQuad"
});
// Use CSS standard easing
Velocity(element, { opacity: 0 }, {
duration: 500,
easing: "ease-out"
});// Elastic bounce effect
Velocity(element, { scale: 1.2 }, {
duration: 800,
easing: "easeOutElastic"
});
// Back overshoot effect
Velocity(element, { translateY: "-100px" }, {
duration: 600,
easing: "easeInOutBack"
});
// Bounce landing effect
Velocity(element, { translateY: "0px" }, {
duration: 900,
easing: "easeOutBounce"
});// Generate custom bezier easing
const customEasing = Velocity.Easings.generateBezier(0.25, 0.46, 0.45, 0.94);
Velocity(element, { rotateZ: "360deg" }, {
duration: 1200,
easing: customEasing
});
// Or use bezier array directly
Velocity(element, { translateX: "300px" }, {
duration: 1000,
easing: [0.68, -0.55, 0.265, 1.55] // Back ease out
});// Different easing for each property using array notation
Velocity(element, {
translateX: ["0px", "200px", "easeOutQuad"],
translateY: ["0px", "-100px", "easeInBounce"],
rotateZ: ["0deg", "180deg", "easeInOutElastic"],
opacity: [1, 0.5, "linear"]
}, 1500);// Custom spring with high tension, low friction (snappy)
const snappySpring = Velocity.Easings.spring(300, 10);
Velocity(element, { scale: 1.5 }, {
duration: 800,
easing: snappySpring
});
// Custom spring with low tension, high friction (smooth)
const smoothSpring = Velocity.Easings.spring(100, 25);
Velocity(element, { translateX: "250px" }, {
duration: 1200,
easing: smoothSpring
});// Register a custom easing function
Velocity.Easings.myCustomEasing = function(t, b, c, d) {
// t = current time
// b = start value
// c = change in value
// d = duration
return c * Math.sin(t / d * Math.PI / 2) + b;
};
// Use the custom easing
Velocity(element, { opacity: 0 }, {
duration: 1000,
easing: "myCustomEasing"
});// Compare different easings on similar animations
const elements = document.querySelectorAll(".comparison");
// Linear movement
Velocity(elements[0], { translateX: "200px" }, { easing: "linear" });
// Ease out for natural deceleration
Velocity(elements[1], { translateX: "200px" }, { easing: "easeOutQuad" });
// Bounce for playful effect
Velocity(elements[2], { translateX: "200px" }, { easing: "easeOutBounce" });
// Elastic for attention-grabbing effect
Velocity(elements[3], { translateX: "200px" }, { easing: "easeOutElastic" });Install with Tessl CLI
npx tessl i tessl/npm-velocity-animate