GSAP Animations: Creating Smooth, Professional Web Animations
Master GSAP for creating stunning animations and interactions. Learn timelines, tweens, and best practices for smooth performance.
11 min read
Master GSAP for creating stunning animations and interactions. Learn timelines, tweens, and best practices for smooth performance.
11 min read
GSAP (GreenSock Animation Platform) is the industry-standard JavaScript animation library. Let's explore how to create smooth, professional animations.
GSAP provides a simple yet powerful API for animating anything:
import gsap from 'gsap';
// Basic animation
gsap.to('.box', { duration: 1, x: 100, opacity: 0.5 });
// From animation (starting point)
gsap.from('.box', { duration: 1, opacity: 0, y: 20 });
// Combining to and from
gsap.fromTo('.box',
{ opacity: 0, y: 20 },
{ opacity: 1, y: 0, duration: 1 }
);
Timelines let you sequence animations:
const tl = gsap.timeline();
tl.to('.box1', { x: 100, duration: 1 })
.to('.box2', { x: 100, duration: 1 }, '-=0.5') // Start 0.5s before box1 ends
.to('.box3', { x: 100, duration: 1 });
Easing creates natural motion:
Animate multiple elements with delays:
gsap.to('.item', {
duration: 0.5,
opacity: 1,
y: 0,
stagger: 0.1, // 0.1s between each animation
ease: 'power2.out',
});
Trigger animations on scroll with ScrollTrigger:
gsap.registerPlugin(ScrollTrigger);
gsap.to('.element', {
scrollTrigger: {
trigger: '.element',
start: 'top center',
end: 'bottom center',
scrub: 1,
},
rotation: 360,
opacity: 1,
});
Use GSAP with React safely:
import gsap from 'gsap';
import { useEffect, useRef } from 'react';
function AnimatedBox() {
const boxRef = useRef(null);
useEffect(() => {
gsap.to(boxRef.current, { x: 100, duration: 1 });
}, []);
return <div ref={boxRef} className="box" />;
}
GSAP empowers you to create engaging, smooth animations that enhance user experience. With proper implementation, animations can make your website feel polished and professional.
If you're interested in discussing web development, design, or want to collaborate on a project, let's connect.
Questions about a project? Start here.
Ibad Khan — PortfolioCompiling interface