"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > "Day ith GSAP: Interactive Scrolling Animation with Rotating Arrows"

"Day ith GSAP: Interactive Scrolling Animation with Rotating Arrows"

Published on 2024-12-22
Browse:123

Introduction

? Hello Developers!

Welcome to Day 7 of my GSAP Journey, where I explore the infinite possibilities of animations on the web. Today, I took on the challenge of creating an interactive scroll-based marquee animation featuring dynamic text and rotating arrows.

With GSAP's powerful animation tools, we’ll make the page respond to user scroll direction—up or down—with seamless movement and rotation. Let’s dive in!


What We’re Building ?️

Our animation will include:

  • A scrolling marquee of text and images.
  • Responsive animations that adjust based on the scroll direction.
  • Rotating arrows to add flair!

You can view the live demo here.


HTML Structure

Here’s the simple HTML markup I used:



    
    
    Day-7 Scrolling Text Animation
    


    


JavaScript Animation with GSAP

Here’s the GSAP-powered JavaScript code that makes the magic happen:

window.addEventListener("wheel", function (dets) { 
    if (dets.deltaY > 0) {
        // Scrolling Down
        gsap.to(".marque", {
            x: "-200%", 
            duration: 4,
            repeat: -1, 
            ease: "none", 
        });
        gsap.to(".marque img", {
            rotate: 180
        });
    } else {
        // Scrolling Up
        gsap.to(".marque", {
            x: "0%", 
            duration: 4,
            repeat: -1, 
            ease: "none", 
        });
        gsap.to(".marque img", {
            rotate: 0
        });
    }
});

How It Works ⚙️

  1. Event Listener: The window.addEventListener("wheel") detects the scroll direction.
  2. GSAP Animations:
    • gsap.to() moves the marquee in a specific direction.
    • The rotation of arrows adds a dynamic, interactive feel.
  3. Infinite Scrolling: Using repeat: -1 ensures the marquee keeps looping endlessly.

Challenges & Learnings

? Challenge: Synchronizing the scroll direction with marquee movement was tricky.

? Solution: GSAP’s robust API made it easy to fine-tune the animations with properties like repeat, ease, and duration.


Final Thoughts

This project showed how GSAP can handle scroll-based interactions and bring webpages to life. Whether you’re working on a personal portfolio or a creative website, GSAP is the perfect tool to make animations engaging and intuitive.

? Try it yourself and share your creations!


Resources

  • GSAP Documentation
  • Live Demo
  • Source Code on GitHub

Release Statement This article is reproduced at: https://dev.to/anticoder03/day-7-with-gsap-interactive-scrolling-animation-with-rotating-arrows-4cld?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3