GSAP
GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web
Top Related Projects
JavaScript animation engine
The motion graphics toolbelt for the web
JavaScript/TypeScript animation engine
Tools for smoother shape animations.
The most versatile JavaScript typewriter effect library on the planet.
Javascript library to create physics-based animations
Quick Overview
GSAP (GreenSock Animation Platform) is a robust JavaScript animation library that enables developers to create high-performance, professional-grade animations for the web. It offers a wide range of tools and plugins to animate CSS properties, SVGs, and more, with cross-browser compatibility and exceptional ease of use.
Pros
- Extremely powerful and flexible, capable of handling complex animations
- High-performance, optimized for smooth animations even on mobile devices
- Extensive plugin ecosystem for advanced features like ScrollTrigger and Draggable
- Excellent documentation and community support
Cons
- Learning curve can be steep for beginners
- Some advanced features require paid Club GreenSock membership
- File size may be a concern for projects that only need basic animations
- Overkill for simple animations that can be achieved with CSS
Code Examples
- Basic Tween:
gsap.to(".box", {duration: 1, x: 100, y: 100, rotation: 360});
This animates an element with class "box" to move 100 pixels right and down while rotating 360 degrees over 1 second.
- Timeline Animation:
let tl = gsap.timeline();
tl.to(".box1", {duration: 1, x: 100})
.to(".box2", {duration: 1, y: 50}, "-=0.5")
.to(".box3", {duration: 1, rotation: 360});
This creates a sequence of animations using a timeline, with some overlap between animations.
- ScrollTrigger Example:
gsap.to(".parallax", {
scrollTrigger: {
trigger: ".parallax",
start: "top bottom",
end: "bottom top",
scrub: true
},
y: (i, target) => -ScrollTrigger.maxScroll(window) * target.dataset.speed,
ease: "none"
});
This creates a parallax effect on elements with class "parallax" based on scroll position.
Getting Started
- Include GSAP in your project:
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.4/gsap.min.js"></script>
- Create a simple animation:
gsap.to(".myElement", {duration: 2, x: 100});
This will move the element with class "myElement" 100 pixels to the right over 2 seconds.
Competitor Comparisons
JavaScript animation engine
Pros of Anime
- Lightweight and minimal, with a smaller file size
- Easier to learn and use for beginners
- Free and open-source
Cons of Anime
- Less feature-rich compared to GSAP
- Smaller community and ecosystem
- Limited support for complex animations and advanced techniques
Code Comparison
GSAP:
gsap.to(".box", {duration: 2, x: 300, rotation: 360, ease: "bounce.out"});
Anime:
anime({
targets: '.box',
translateX: 300,
rotate: 360,
duration: 2000,
easing: 'easeOutBounce'
});
Both libraries offer similar syntax for basic animations, but GSAP provides more advanced features and a wider range of easing functions. Anime's syntax is slightly more verbose but still relatively easy to understand.
GSAP excels in performance, especially for complex animations, and offers a more comprehensive set of tools for professional-grade projects. It also has better browser support and a larger community.
Anime, on the other hand, is a good choice for simpler projects or developers who prefer a more lightweight solution. It's easier to get started with and can handle most common animation needs effectively.
The motion graphics toolbelt for the web
Pros of mojs
- Focuses on motion graphics and offers unique shape modules for creating custom animations
- Provides a visual timeline editor for easier animation sequencing and tweaking
- Has a smaller file size, which can be beneficial for projects with strict performance requirements
Cons of mojs
- Less comprehensive documentation and community support compared to GSAP
- Fewer built-in easing functions and plugins
- Not as actively maintained, with less frequent updates and bug fixes
Code Comparison
GSAP:
gsap.to(".box", {
duration: 1,
x: 100,
y: 50,
rotation: 360,
ease: "bounce.out"
});
mojs:
const tween = new mojs.Tween({
duration: 1000,
onUpdate: (progress) => {
const x = 100 * progress;
const y = 50 * progress;
const rotation = 360 * progress;
// Apply transformations to the element
}
});
Both libraries offer powerful animation capabilities, but GSAP provides a more straightforward API for common animations, while mojs excels in creating complex motion graphics and custom shapes. GSAP has a larger ecosystem and more extensive documentation, making it easier for beginners to get started. However, mojs offers unique features like the visual timeline editor, which can be particularly useful for designers and those who prefer a more visual approach to animation creation.
JavaScript/TypeScript animation engine
Pros of tween.js
- Lightweight and simple, with a smaller file size
- Open-source and free to use for all projects
- Easy to integrate with other libraries and frameworks
Cons of tween.js
- Limited features compared to GSAP
- Less robust documentation and community support
- Fewer advanced animation capabilities and plugins
Code Comparison
tween.js:
var tween = new TWEEN.Tween(object)
.to({ x: 100, y: 100 }, 1000)
.easing(TWEEN.Easing.Quadratic.Out)
.start();
GSAP:
gsap.to(object, {
duration: 1,
x: 100,
y: 100,
ease: "power2.out"
});
Both libraries offer similar basic functionality for creating tweens, but GSAP provides a more concise and readable syntax. GSAP also offers a wider range of easing functions and animation properties out of the box.
While tween.js is a solid choice for simple animations and projects with size constraints, GSAP offers more advanced features, better performance, and a more comprehensive ecosystem for complex animations and interactive experiences.
Tools for smoother shape animations.
Pros of Flubber
- Specialized in shape morphing and interpolation
- Lightweight and focused on a specific task
- Easy to integrate with other animation libraries
Cons of Flubber
- Limited to shape morphing, not a full-featured animation library
- Smaller community and fewer resources compared to GSAP
- Less frequent updates and maintenance
Code Comparison
Flubber:
import { interpolate } from 'flubber';
const interpolator = interpolate(shape1, shape2);
const midwayShape = interpolator(0.5);
GSAP:
import { gsap } from 'gsap';
gsap.to("#myElement", {
duration: 1,
x: 100,
y: 50,
rotation: 360
});
Summary
Flubber is a specialized library for shape morphing and interpolation, making it ideal for specific use cases involving SVG shape transitions. It's lightweight and can be easily integrated with other animation libraries. However, it lacks the comprehensive feature set of GSAP, which offers a wide range of animation capabilities beyond shape morphing. GSAP provides a more robust ecosystem, frequent updates, and extensive documentation, making it a more versatile choice for general animation needs. The code comparison illustrates the focused nature of Flubber compared to the broader animation capabilities of GSAP.
The most versatile JavaScript typewriter effect library on the planet.
Pros of TypeIt
- Focused specifically on typewriter effects, making it simpler to use for this purpose
- Lightweight and has no dependencies
- Offers a more straightforward API for creating typing animations
Cons of TypeIt
- Limited to typewriter animations, while GSAP offers a wide range of animation capabilities
- Less robust community support and ecosystem compared to GSAP
- Fewer advanced features and customization options
Code Comparison
TypeIt:
new TypeIt("#element", {
strings: "This is a typewriter effect!",
speed: 50,
waitUntilVisible: true
}).go();
GSAP:
gsap.to("#element", {
duration: 2,
text: "This is a typewriter effect!",
ease: "none",
scrollTrigger: {
trigger: "#element",
start: "top 80%"
}
});
Both libraries can create typewriter effects, but GSAP requires the TextPlugin for text animations. TypeIt provides a more straightforward API for this specific use case, while GSAP offers greater flexibility for various animation types. GSAP's ecosystem and extensive features make it more suitable for complex animations, while TypeIt excels in simplicity for typewriter effects.
Javascript library to create physics-based animations
Pros of dynamics.js
- Lightweight and focused on physics-based animations
- Simple API with intuitive parameters for natural-looking motion
- No dependencies, making it easy to integrate into projects
Cons of dynamics.js
- Limited feature set compared to GSAP's comprehensive toolkit
- Less active development and community support
- Fewer animation options and less flexibility for complex animations
Code Comparison
dynamics.js:
dynamics.animate(element, {
translateX: 100,
scale: 1.2
}, {
type: dynamics.spring,
frequency: 200,
friction: 200,
duration: 1500
});
GSAP:
gsap.to(element, {
x: 100,
scale: 1.2,
duration: 1.5,
ease: "elastic.out(1, 0.3)"
});
Both libraries offer ways to create smooth animations, but GSAP provides more advanced features and a wider range of easing options. dynamics.js focuses on physics-based animations with intuitive parameters, while GSAP offers a more comprehensive animation toolkit with additional plugins and capabilities.
dynamics.js is ideal for projects requiring simple, natural-looking animations without the need for a full-featured animation library. GSAP, on the other hand, is better suited for complex animations and projects that require a broader range of animation capabilities.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
GSAP (GreenSock Animation Platform)
GSAP is a framework-agnostic JavaScript animation library that turns developers into animation superheroes. Build high-performance animations that work in every major browser. Animate CSS, SVG, canvas, React, Vue, WebGL, colors, strings, motion paths, generic objects...anything JavaScript can touch! GSAP's ScrollTrigger plugin delivers jaw-dropping scroll-based animations with minimal code. gsap.matchMedia() makes building responsive, accessibility-friendly animations a breeze.
No other library delivers such advanced sequencing, reliability, and tight control while solving real-world problems on over 12 million sites. GSAP works around countless browser inconsistencies; your animations just work. At its core, GSAP is a high-speed property manipulator, updating values over time with extreme accuracy. It's up to 20x faster than jQuery!
GSAP is completely flexible; sprinkle it wherever you want. Zero dependencies.
There are many optional plugins and easing functions for achieving advanced effects easily like scrolling, morphing, animating along a motion path or FLIP animations. There's even a handy Observer for normalizing event detection across browsers/devices.
Get Started
Docs & Installation
View the full documentation here, including an installation guide.
CDN
<script src="https://cdn.jsdelivr.net/npm/gsap@3.12/dist/gsap.min.js"></script>
See JSDelivr's dedicated GSAP page for quick CDN links to the core files/plugins. There are more installation instructions at gsap.com.
Every major ad network excludes GSAP from file size calculations and most have it on their own CDNs, so contact them for the appropriate URL(s).
NPM
See the guide to using GSAP via NPM here.
npm install gsap
GSAP's core can animate almost anything including CSS and attributes, plus it includes all of the utility methods like interpolate(), mapRange(), most of the eases, and it can do snapping and modifiers.
// typical import
import gsap from "gsap";
// get other plugins:
import ScrollTrigger from "gsap/ScrollTrigger";
import Flip from "gsap/Flip";
import Draggable from "gsap/Draggable";
// or all tools are exported from the "all" file (excluding members-only plugins):
import { gsap, ScrollTrigger, Draggable, MotionPathPlugin } from "gsap/all";
// don't forget to register plugins
gsap.registerPlugin(ScrollTrigger, Draggable, Flip, MotionPathPlugin);
The NPM files are ES modules, but there's also a /dist/ directory with UMD files for extra compatibility.
Download Club GSAP members-only plugins from your gsap.com account and then include them in your own JS payload. There's even a tarball file you can install with NPM/Yarn. GSAP has a private NPM registry for members too. Post questions in our forums and we'd be happy to help.
ScrollTrigger & ScrollSmoother
If you're looking for scroll-driven animations, GSAP's ScrollTrigger plugin is the new standard. There's a companion ScrollSmoother as well.
Using React?
There's a @gsap/react package that exposes a useGSAP()
hook which is a drop-in replacement for useEffect()
/useLayoutEffect()
, automating cleanup tasks. Please read the React guide for details.
Resources
- gsap.com
- Getting started guide
- Docs
- Demos & starter templates
- Community forums
- Ease Visualizer
- Showcase
- YouTube Channel
- Cheat sheet
- Try bonus plugins for free
- Club GSAP (get access to unrestricted bonus plugins that are not in this repository)
What is Club GSAP?
There are 3 main reasons anyone signs up for Club GSAP:
- To get access to snazzy members-only plugins like MorphSVG, SplitText, ScrollSmoother, etc.
- To get the special commercial license.
- To support ongoing development efforts and cheer us on.
Try all bonus plugins for free!
Need help?
Ask in the friendly GSAP forums. Or share your knowledge and help someone else - it's a great way to sharpen your skills! Report any bugs there too (or file an issue here if you prefer).
License
GreenSock's standard "no charge" license can be viewed at https://gsap.com/standard-license. Club GSAP members are granted additional rights. See https://gsap.com/licensing/ for details. Why doesn't GSAP use an MIT (or similar) open source license, and why is that a good thing? This article explains it all: https://gsap.com/why-license/
Copyright (c) 2008-2023, GreenSock. All rights reserved.
Top Related Projects
JavaScript animation engine
The motion graphics toolbelt for the web
JavaScript/TypeScript animation engine
Tools for smoother shape animations.
The most versatile JavaScript typewriter effect library on the planet.
Javascript library to create physics-based animations
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot