DEV Community

Cover image for Day 1: Exploring GSAP Basics and Timelines ๐Ÿš€
Ashish prajapati
Ashish prajapati

Posted on

Day 1: Exploring GSAP Basics and Timelines ๐Ÿš€

Welcome to my GSAP learning journey! In this series, I'll share my progress as I explore the GreenSock Animation Platform (GSAP). Today, I started with the basics of GSAP's animation capabilities, focusing on gsap.to, gsap.from, and timelines.


๐ŸŸข GSAP Basics: to and from

GSAP provides intuitive methods for creating animations:

  1. Animating Properties Animate the position, rotation, color, and scale of an element:
   gsap.to("#box", {
       x: 500,
       y: 500,
       duration: 2,
   });
Enter fullscreen mode Exit fullscreen mode
  1. Animating with Delay Add a delay for smoother animation sequences:
   gsap.from("#box2", {
       x: 800,
       y: 500,
       duration: 2,
       delay: 2,
   });
Enter fullscreen mode Exit fullscreen mode
  1. Combining Multiple Effects Enhance the animation with multiple transformations:
   gsap.to("#box", {
       rotate: 360,
       backgroundColor: "blue",
       borderRadius: "50%",
       scale: 0.75,
       duration: 2,
   });
Enter fullscreen mode Exit fullscreen mode

๐Ÿ” Looping and Yoyo Effects

Create infinite loops and oscillating animations using repeat and yoyo:

gsap.to("#box", {
    x: 1200,
    rotate: 360,
    delay: 1,
    duration: 2,
    repeat: -1, // Infinite loop
    yoyo: true, // Reverses animation
});
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”„ Managing Complex Animations: GSAP Timelines

Timelines allow chaining animations for better control and synchronization. Hereโ€™s how I created a sequence of animations:

  1. Simple Timeline
   var tl = gsap.timeline();
   tl.to("#box", {
       x: 1000,
       rotate: 360,
       duration: 2,
       backgroundColor: "blue",
   });
   tl.to("#box2", {
       x: 1000,
       rotate: 360,
       duration: 2,
       backgroundColor: "lightblue",
   });
   tl.to("#box3", {
       x: 1000,
       rotate: 360,
       duration: 2,
       backgroundColor: "lightgreen",
   });
Enter fullscreen mode Exit fullscreen mode
  1. Animating Navigation Elements I also used timelines for staggered animations of a navigation bar:
   var tl = gsap.timeline();
   tl.from(".logo", {
       y: "-30px",
       opacity: 0,
       duration: 1,
       delay: 1,
   });
   tl.from(".links h4", {
       y: "-30px",
       opacity: 0,
       duration: 1,
       stagger: 0.5,
   });
   tl.from(".main", {
       y: "-30px",
       opacity: 0,
       duration: 1,
       scale: 0.3,
   });
Enter fullscreen mode Exit fullscreen mode

๐ŸŽฏ Key Takeaways from Day 1

  • gsap.to animates from the current state to the target state.
  • gsap.from animates from the target state to the current state.
  • Timelines simplify the creation of synchronized animations.

๐ŸŽจ Final Project Demo

Check out the live demo of what I created on Day 1:

๐Ÿ‘‰ Day 1 GSAP Demo


๐Ÿ“‚ GitHub Repository

Explore the source code for the Day 1 project on GitHub:

๐Ÿ‘‰ GitHub: GSAP Basics


This is just the beginning! In the coming days, I'll dive deeper into advanced GSAP features. Stay tuned for Day 2! ๐Ÿš€

Let me know what you think and share your tips in the comments below!

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more