When animating in GSAP, easing plays a crucial role in controlling how an animation starts, proceeds, and ends. While standard ease types are great, sometimes you need more control over the animation’s timing curve. This is where GSAP’s CustomEase plugin shines, allowing you to create custom easing curves that make animations feel exactly as you envision.
What Is CustomEase?
CustomEase is a plugin for GSAP (GreenSock Animation Platform) that lets you define our own easing curves through a Bézier path or points, enabling the animation to follow a precise path. This is particularly useful for custom transitions and effects that don’t match typical easing behaviors.
Key benefits:
- Create any type of ease, from complex “bounces” to specific acceleration and deceleration points.
- Gain flexibility beyond preset ease types.
- Smoothly adjust or tweak easing in real-time for the desired effect.
Setting Up CustomEase
Before using CustomEase, make sure it’s included in the GSAP project. The GSAP plugin suite includes CustomEase for its subscribers, or we can use it via a CDN for quick testing.
CDN setup:
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.4/gsap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.4/CustomEase.min.js"></script>
Creating our first CustomEase
The basic syntax for creating a CustomEase is straightforward. Here’s an example of setting up a simple ease:
gsap.registerPlugin(CustomEase);
CustomEase.create("myEase", "M0,0 C0.25,1 0.5,0.5 1,1");
// Using "myEase" in an animation
gsap.to(".box", { duration: 2, x: 400, ease: "myEase" });
The curve’s path "M0,0 C0.25,1 0.5,0.5 1,1" represents control points on a Bézier curve:
- The “M” indicates the start point (x=0, y=0).
- “C” indicates the control points, which dictate the curve’s shape.
- The final point (x=1, y=1) represents the end.
These points are defined within a coordinate system where:
- The x-axis (0 to 1) represents time progress.
- The y-axis (0 to 1) represents animation progress.
Understanding CustomEase Syntax: Bézier Curves Explained
Each curve in CustomEase is defined using Bézier control points, which determine how fast or slow the animation will be at any given time. A simple CustomEase path "M0,0 C0.25,1 0.5,0.5 1,1" contains three parts:
"M0,0": The “move-to” command, starting the curve at (0,0)."C0.25,1 0.5,0.5 1,1": The “curve-to” command, specifying control points and the end point.
Here’s a breakdown of control points:
- First control point (0.25, 1) dictates the curve’s entry speed.
- Second control point (0.5, 0.5) determines the midpoint behavior.
- End point (1,1) is where the curve completes.
Creating a CustomEase with an Online Editor
GSAP’s CustomEase Editor provides an intuitive way to create these curves visually:
- Visit the CustomEase visual editor on the GreenSock website.
- Adjust control points on the graph to change the easing.
- Copy the resulting path string, which will look something like
"M0,0 C0.5,1 0.5,1 1,1". - Use this path string with
CustomEase.create()in your project.
Advanced CustomEase Usage Examples
1. Bouncing Ease
CustomEase is great for adding elasticity or bounce to animations. Here’s a simple example:
CustomEase.create("bounceEase", "M0,0 C0.25,1.5 0.75,-0.5 1,1");
gsap.to(".ball", { duration: 2, y: 300, ease: "bounceEase" });
This curve:
- Starts with a high upward movement (
C0.25,1.5). - Pulls back down before moving up again (
0.75,-0.5). - Ends smoothly at the target position (1,1).
2. Elastic Spring Effect
For a springy effect that overshoots and then returns to the target, we can set up CustomEase like this:
CustomEase.create("springEase", "M0,0 C0.4,-0.5 0.6,1.5 1,1");
gsap.to(".spring", { duration: 2, x: 500, ease: "springEase" });
The “C0.4,-0.5” and “0.6,1.5” control points create a back-and-forth effect, similar to a spring recoiling.
3. Asymmetric Acceleration/Deceleration
If we want the animation to ease in quickly and then slow down, we can create an asymmetric ease:
CustomEase.create("quickStartEase", "M0,0 C0.7,0 0.3,1 1,1");
gsap.to(".box", { duration: 2, x: 300, ease: "quickStartEase" });
This setup provides a fast start and then smooth deceleration, useful for creating responsive-feeling interactions or emphasizing the beginning of an animation.
Tuning CustomEase for Precision
You can add multiple control points for more complex behavior. Here’s a CustomEase that combines a sharp acceleration, a slight bounce, and a gentle end:
CustomEase.create("complexEase", "M0,0 C0.2,1 0.4,-1 0.6,1 1,1");
gsap.to(".element", { duration: 3, x: 400, ease: "complexEase" });
Each pair of control points adds a segment to the curve, creating layers of motion such as bounce or elasticity. By manipulating these values, you can blend multiple types of ease into a single path.
Visual Debugging with GSAP’s Ease Visualizer
To visualize and debug your CustomEase functions:
- Use GSAP’s Ease Visualizer, accessible on the GSAP documentation page.
- Copy your custom path into the visualizer.
- Observe the resulting curve and tweak as necessary.
Example Debugging Scenario
If your animation starts too slowly, check if the initial control points have too steep a rise. Adjusting x values for the initial control point to be closer to zero can smoothen the entry.
Tips for Effective Use of CustomEase
- Test small values: Small control point adjustments often make a big difference.
- Match ease style to content: A bouncy ease might suit an elastic object but look out of place on a button fade-in.
- Utilize CustomEase chaining: You can combine
CustomEasewith GSAP timelines for even more complex animations, like layering ease effects across different elements.