What is the cubic Bézier easing in Anime.js?
What is easing?
An easing is the rate of change in animation progress. In Anime.js, we can use a user-defined cubic Bézier curve to create an easing.
A cubic Bézier curve is a smooth curve defined by four points:
Here,
Syntax
The following is the syntax to create a cubic Bézier easing:
anime({
...
easing: 'cubicBezier(x1, y1, x2, y2)',
});
The cubicBezier value takes four parameters. The x1 and y1 parameters are coordinates of x2 and y2 are coordinates of
Example
For the following example, we create a simple sliding box animation and set its easing to follow the cubic Bézier curve given below:
Explanation
In the HTML section, we create a box using a div element and style it using the box class.
In the JavaScript section, we create the animation using the anime() function.
- Line 2: We target the div element using its
boxclass. - Lines 3–5: We set parameters to control the box's horizontal movement and timing.
- Line 6: We set the
easingparameter to'cubicBezier'. We pass the coordinates ofand as described in the previous illustration.
As we can see, the progression of the animation mimics the cubic Bézier curve. The box slows down to a stop at the midpoint and then speeds up to the finish point.
In the same manner, any cubic Bézier curve can be used as an easing by providing coordinates for
Free Resources