GSAP (GreenSock Animation Platform)

website·Indexed 40 days ago

https://gsap.com/docs/v3/

A robust JavaScript animation library for professionals. GSAP v3 provides high-performance property setting via Tweens and Timelines, featuring a comprehensive suite of easing functions, utility methods, and core plugins for animating CSS properties, attributes, and complex sequences.

Tokens
176.5K
Snippets
896
Records
1.3K
Agent score
72%

What's inside GSAP

  1. Overview of GSAP Physics2DPlugin

    v3
    The Physics2DPlugin provides simple physics functionality for tweening an object's x and y coordinates (or alternative properties like left and top). It is designed for creating physics-based visual effects rather than as a full-blown physics engine; notably, it does not offer collision detection. Any easing equations defined for the tween are ignored when using physics2D properties.
  2. Overview of gsap.utils utility functions

    v3
    The gsap.utils object contains a set of helper functions for managing numeric behaviors, mathematical operations, and range manipulation. A key feature of many gsap.utils methods is that they can optionally return functions instead of static values. When a function is returned and plugged into a tween, GSAP executes that function for each individual target, allowing for dynamic, per-target end values rather than a single shared value.
  3. Overview of GSAP Flip Plugin

    v3
    The Flip plugin (added in v3.9.0) implements the 'First, Last, Invert, Play' (FLIP) animation technique. It allows developers to transition elements between two states—even with sweeping DOM structure changes—without the elements jumping. It works by recording the current position, size, and rotation, allowing the developer to make DOM changes, and then animating the removal of offsets to create a seamless transition.
  4. Use GSAP utility methods in tweens

    v3
    GSAP utility methods can optionally return functions instead of static values. When a utility method returns a function and is plugged directly into a tween, GSAP executes that function once for each target. This allows different targets in the same tween to have unique values calculated by the utility, rather than sharing a single global end value.
  5. GSAP Specialized Plugins Overview

    v3.md

    GSAP extends its core functionality through specialized plugins. Key categories include:

    Scroll Plugins:

    • ScrollTrigger: Trigger animations based on scroll position.
    • ScrollTo: Animate scrolling to a specific element or position.
    • ScrollSmoother: Adds smooth scrolling (requires ScrollTrigger).

    Text Plugins:

    • SplitText: Splits text into lines, words, or characters.
    • ScrambleText: Creates a scrambling text effect.
    • TextPlugin: Replaces text content.

    SVG Plugins:

    • DrawSVG: Animates the drawing of SVG strokes.
    • MorphSVG: Morphs one SVG shape into another.
    • MotionPath: Animates elements along a path.

    UI Plugins:

    • Flip: Simplifies animating elements between different layouts.
    • Draggable: Enables dragging of elements.
    • Inertia: Adds momentum/inertia to animations.
    • Observer: Detects events like scroll, mouse wheel, or touch without requiring actual scroll movement.
  6. Create responsive animations with gsap.matchMedia()

    v3
    Introduced in v3.11.0, gsap.matchMedia() allows you to wrap GSAP animations and ScrollTriggers in a function that only executes when a specific media query matches. When the media query no longer matches, all animations and ScrollTriggers created within that function are automatically reverted. This is ideal for handling mobile/desktop breakpoints or accessibility preferences like prefers-reduced-motion.
    // Create a MatchMedia instance
    let mm = gsap.matchMedia();
    
    // Add a media query. The function runs when the query matches
    mm.add("(min-width: 800px)", () => {
      gsap.to(".box", { rotation: 360 });
      ScrollTrigger.create({ trigger: ".box", start: "top center" });
    
      return () => {
        // Optional: custom cleanup code that runs when it STOPS matching
      };
    });
    
    // Revert all animations/ScrollTriggers across all matchMedia queries
    mm.revert();
  7. GSAP Core Library Overview

    v3.md
    The GSAP Core provides the essential tools for creating high-performance, responsive animations across all browsers. It includes the primary Tween and Timeline engines. The core is designed to be lightweight, with advanced functionality moved into optional plugins.
  8. GSAP Core capabilities and built-in features

    v3

    GSAP's core library includes essential animation tools without requiring additional plugins. Key built-in capabilities include:

    • Animation Targets: Ability to animate CSS properties, attributes, and array values.
    • Eases: Built-in easing functions such as none, power1 through power4, back, bounce, circ, elastic, expo, sine, and steps(n).
    • Efficiency Tools: Staggers, callbacks, snapping, modifiers, keyframes, and a Ticker with lag smoothing.
    • Lifecycle & Responsivity: gsap.context() and revert() for cleanup, and gsap.matchMedia() for responsive and accessible animations.
    • Utility Methods: A suite of helper functions including clamp(), distribute(), interpolate(), mapRange(), normalize(), random(), selector(), shuffle(), snap(), toArray(), and wrap().
  9. Understand GSAP Plugin architecture

    GSAP uses a plugin system to keep the core library small. Plugins add extra capabilities to the GSAP core, allowing developers to include only the specific features they need for a project.
  10. Control all GSAP animations using gsap.globalTimeline

    v3
    gsap.globalTimeline is the root Timeline instance that drives all animations in GSAP. It can be used to affect all active tweens and timelines simultaneously. Note that gsap.delayedCalls() are also treated as tweens and will be affected by global timeline controls. If you need to exclude delayed calls, use gsap.exportRoot() instead.
  11. Manage and cleanup animations with gsap.context()

    v3
    Introduced in v3.11.0, gsap.context() collects all GSAP animations and ScrollTriggers created within its scope. This allows developers to revert or kill all associated animations at once without tracking individual variables or arrays. This is especially useful for cleanup in framework components (like React or Angular) to return elements to their original state.
    let ctx = gsap.context(() => {
      gsap.to(".box", { x: 100 });
      gsap.from(".circle", { opacity: 0 });
      gsap.timeline().to(".box", { y: 100 }).to(".circle", { scale: 2 });
    });
    
    // Reverts all animations created inside the context to their original state
    ctx.revert();
  12. Implement a modifier function

    v3

    A modifier function receives two parameters that can be used to calculate the final value of a property:

    1. value (number | string): The value that the regular tween is about to apply. This is typically a number (e.g., for x or rotation), but can be a string for properties like left (e.g., "212px") or boxShadow.
    2. target (object): The target object being animated.

    Returning a value from this function overrides the tween's default value for that tick.