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,
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
For the following example, we create a simple sliding box animation and set its easing to follow the cubic Bézier curve given below:
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.
box class.easing parameter to 'cubicBezier'. We pass the coordinates of 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