Get the FREE Ultimate OpenClaw Setup Guide →

gsap

npx machina-cli add skill noklip-io/agent-skills/gsap --openclaw
Files (1)
SKILL.md
6.5 KB

GSAP Best Practices

Professional-grade JavaScript animation library for the modern web. Provides high-performance tweening with powerful sequencing, scroll-based animations, and extensive plugin ecosystem.

Installation

# Core library
npm install gsap

# React hook
npm install @gsap/react

# Register plugins (do once at app entry)
import gsap from 'gsap'
import { ScrollTrigger } from 'gsap/ScrollTrigger'
gsap.registerPlugin(ScrollTrigger)

Quick Start

import gsap from 'gsap'

// Basic tween
gsap.to('.box', { x: 200, duration: 1 })

// From animation
gsap.from('.box', { opacity: 0, y: 50, duration: 0.5 })

// Timeline sequence
const tl = gsap.timeline()
tl.to('.box1', { x: 100 })
  .to('.box2', { x: 100 }, '-=0.5')  // overlap by 0.5s
  .to('.box3', { x: 100 }, '<')       // same start as previous

Core Concepts

ConceptDescription
TweenSingle animation that changes properties over time
TimelineContainer for sequencing tweens with precise control
EaseControls animation velocity curve (default: power1.out)
ScrollTriggerLinks animations to scroll position
PluginExtends GSAP with specialized capabilities

Reference Index

ReferenceUse When
references/00-cheatsheet.mdQuick reference, common operations at a glance
references/01-core.mdBasic tweens, special properties, callbacks, quickTo, ticker
references/02-easing.mdEasing functions, custom eases
references/03-timeline.mdSequencing, positioning, labels, nesting
references/04-stagger.mdStaggered animations, grid distributions
references/05-utilities.mdHelper functions (toArray, clamp, interpolate)
references/06-scrolltrigger.mdScroll-based animations, pin, scrub, snap
references/07-scrollsmoother.mdSmooth scrolling, parallax effects
references/08-splittext.mdText splitting and animation
references/09-svg-plugins.mdDrawSVG, MorphSVG, MotionPath
references/10-flip.mdLayout animations (FLIP technique)
references/11-react.mduseGSAP hook, cleanup, React patterns
references/12-observer-draggable.mdGesture detection, draggable elements
references/13-text-plugins.mdTextPlugin, ScrambleTextPlugin

Common Patterns

Fade In on Load

gsap.from('.hero', {
  opacity: 0,
  y: 30,
  duration: 1,
  ease: 'power2.out'
})

Staggered List Animation

gsap.from('.list-item', {
  opacity: 0,
  y: 20,
  stagger: 0.1,
  duration: 0.5
})

Scroll-Triggered Animation

gsap.registerPlugin(ScrollTrigger)

gsap.to('.box', {
  x: 500,
  scrollTrigger: {
    trigger: '.box',
    start: 'top 80%',
    end: 'top 20%',
    scrub: true
  }
})

Timeline with Controls

const tl = gsap.timeline({ paused: true })
tl.to('.modal', { opacity: 1, scale: 1, duration: 0.3 })
  .from('.modal-content', { y: 20, opacity: 0 }, '-=0.1')

// Control playback
tl.play()
tl.reverse()
tl.progress(0.5)

Critical Mistakes to Avoid

1. Missing Plugin Registration

// ❌ Plugin won't work
import { ScrollTrigger } from 'gsap/ScrollTrigger'
gsap.to('.box', { scrollTrigger: { ... } })

// ✅ Register plugins first
gsap.registerPlugin(ScrollTrigger)
gsap.to('.box', { scrollTrigger: { ... } })

2. React Cleanup Issues

// ❌ Memory leaks, zombie animations
useEffect(() => {
  gsap.to('.box', { x: 100 })
}, [])

// ✅ Use useGSAP hook for automatic cleanup
import { useGSAP } from '@gsap/react'
useGSAP(() => {
  gsap.to('.box', { x: 100 })
}, { scope: containerRef })

3. Conflicting Tweens

// ❌ Two tweens fighting for same property
gsap.to('.box', { x: 100, duration: 2 })
gsap.to('.box', { x: 200, duration: 1 })

// ✅ Use overwrite or kill previous
gsap.to('.box', { x: 100, duration: 2, overwrite: true })
// or
gsap.killTweensOf('.box')
gsap.to('.box', { x: 200, duration: 1 })

4. ScrollTrigger Not Refreshing

// ❌ Layout changes but ScrollTrigger uses old positions
dynamicallyAddContent()

// ✅ Refresh after DOM/layout changes
dynamicallyAddContent()
ScrollTrigger.refresh()

5. Animating Non-Existent Elements

// ❌ Element not in DOM yet
gsap.to('.dynamic-element', { x: 100 })

// ✅ Wait for element or use immediateRender: false
gsap.to('.dynamic-element', {
  x: 100,
  immediateRender: false,
  scrollTrigger: { ... }
})

6. Wrong from() Behavior

// ❌ from() renders immediately, causing flash
gsap.from('.box', { opacity: 0 })

// ✅ Set initial state in CSS or use fromTo
// CSS: .box { opacity: 0; }
gsap.to('.box', { opacity: 1 })

// or use fromTo for explicit control
gsap.fromTo('.box', { opacity: 0 }, { opacity: 1 })

7. Forgetting Selector Scope

// ❌ Affects ALL .box elements on page
gsap.to('.box', { x: 100 })

// ✅ Scope to container
gsap.to('.box', { x: 100 }, { scope: containerRef })
// or use gsap.utils.selector
const q = gsap.utils.selector(container)
gsap.to(q('.box'), { x: 100 })

Quick Reference

TaskSolution
Animate to valuesgsap.to(target, { props })
Animate from valuesgsap.from(target, { props })
Animate both directionsgsap.fromTo(target, { from }, { to })
Set instantlygsap.set(target, { props })
Create timelinegsap.timeline({ options })
Kill all tweensgsap.killTweensOf(target)
Global defaultsgsap.defaults({ ease, duration })
Register plugingsap.registerPlugin(Plugin)
Get by IDgsap.getById('myTween')
Match mediagsap.matchMedia()

Plugin Availability

PluginLicenseDescription
ScrollTriggerFreeScroll-based animations
ObserverFreeGesture/scroll detection
DraggableFreeDrag interactions
FlipFreeLayout animations
TextPluginFreeText content animation
ScrollSmootherClubSmooth scrolling
SplitTextClubText splitting
DrawSVGClubSVG stroke animation
MorphSVGClubSVG morphing
MotionPathClubPath-based motion
ScrollToFreeScroll to position

Source

git clone https://github.com/noklip-io/agent-skills/blob/main/skills/gsap/SKILL.mdView on GitHub

Overview

GSAP is a professional-grade JavaScript animation library for modern web apps. It delivers high-performance tweens, robust timelines, and a rich plugin ecosystem (including ScrollTrigger, ScrollSmoother, SplitText, Flip, DrawSVG, MorphSVG, MotionPath), enabling complex, synchronized animations across UI, SVGs, and layouts.

How This Skill Works

GSAP creates interpolations (tweens) that smoothly transition element properties over time. Timelines sequence multiple tweens with precise control, while plugins extend capabilities (e.g., ScrollTrigger links animations to scroll, SplitText animates text, DrawSVG and MorphSVG animate SVG paths). In React apps, the @gsap/react useGSAP hook helps manage lifecycles and cleanup; plugins are registered once at app entry.

When to Use It

  • Animate UI elements and micro-interactions with precise tweening.
  • Sequence complex animations using Timeline for coordinated entrances, modals, or carousels.
  • Create scroll-based effects with ScrollTrigger or ScrollSmoother for parallax, reveal-on-scroll, or sticky sections.
  • Animate SVGs and vector paths with DrawSVG, MorphSVG, or MotionPath.
  • Implement responsive layout transitions and state changes using FLIP and related GSAP plugins.

Quick Start

  1. Step 1: Install GSAP and required plugins (e.g., npm install gsap @gsap/react).
  2. Step 2: Register plugins at app entry (import gsap from 'gsap'; import { ScrollTrigger } from 'gsap/ScrollTrigger'; gsap.registerPlugin(ScrollTrigger)).
  3. Step 3: Create a basic animation or timeline (e.g., gsap.to('.box', { x: 200, duration: 1 }); or const tl = gsap.timeline(); tl.to('.box', { opacity: 1, duration: 0.5 });

Best Practices

  • Register necessary plugins (e.g., ScrollTrigger) once at app startup.
  • Prefer GSAP timelines for sequencing over chained animations for maintainability.
  • In React, use the useGSAP hook from @gsap/react to handle cleanup automatically.
  • Group related animations in a shared timeline to keep start/end synchronized.
  • Test performance, keep tweens lightweight, and avoid animating off-screen elements unnecessarily.

Example Use Cases

  • Fade in a hero section on page load with a subtle upward motion.
  • Staggered entrance of list items to create a polished reveal effect.
  • Scroll-triggered reveal and parallax on a hero image using ScrollTrigger.
  • Modal workflow controlled by a single timeline: open, animate content, then close.
  • SVG path drawing or morphing using DrawSVG/MorphSVG during an onboarding flow.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers