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

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

SurveyJS custom survey software

JavaScript UI Library for Surveys and Forms

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

View demo

๐Ÿ‘‹ Kindness is contagious

Please leave a โค๏ธ or a friendly comment on this post if you found it helpful!

Okay