cubicBezier() function allows you to create custom easing curves using cubic bezier control points. It’s adapted from Gaëtan Renaudeau’s bezier-easing.
Basic Usage
Parameters
The x coordinate of the first control point. Defines the horizontal position of the first bezier handle.
The y coordinate of the first control point. Defines the vertical position of the first bezier handle.
The x coordinate of the second control point. Defines the horizontal position of the second bezier handle.
The y coordinate of the second control point. Defines the vertical position of the second bezier handle.
Common Presets
Ease
Ease In
Ease Out
Ease In Out
Custom Curves
Anticipation
Creates an animation that pulls back slightly before moving forward:Fast Start, Slow End
Slow Start, Fast End
Understanding Cubic Bezier
A cubic bezier curve is defined by four points:- Start point:
(0, 0)- always fixed - First control point:
(mX1, mY1)- controls the curve at the start - Second control point:
(mX2, mY2)- controls the curve at the end - End point:
(1, 1)- always fixed
Tips
- X coordinates control the timing distribution
- Y coordinates control the value progression
- Y values can go below 0 or above 1 to create overshoot effects
- When
mX1 === mY1andmX2 === mY2, the function returns a linear easing
Creating Bezier Curves
You can use online tools to visualize and create cubic bezier curves:- cubic-bezier.com
- Chrome DevTools Animation Inspector
Algorithm Details
The implementation uses:- Binary subdivision for high precision curve calculation
- Iteration continues until precision reaches 0.0000001 or 100 iterations
- Optimized for performance with minimal calculations
Reusable Curves
Performance
The cubic bezier function is highly optimized:- Uses binary subdivision for accurate interpolation
- Caches calculation results for
t === 0andt === 1 - Returns the linear function directly when control points form a straight line
See Also
- Easing Functions - Built-in easing presets
- Spring Easing - Physics-based spring animations