Jump to content
Search Community

How to use scroll trigger to trigger the timeline when there are multiple elements

Vasanth test
Moderator Tag

Go to solution Solved by Vasanth,

Recommended Posts

Hi,

 

I started using gsap scroll trigger and i have some confusions on using it when there a multiple elements. In my case there are three div with same class name " wrap-container". Inside each wrap container there are one div with class "reveal-img" and "reveal-text". Attached my codepen link

 

Can you please help me on triggering timeline when user scrolls to each wrap container div? I have tried and they are all executing at once.

 

Using scroll magic and gsap they have achieved this, but i am not able to do it using scroll trigger

 

Attached the code of scrollmagic and gsap

<let controller;
let slideScene;
 
function animateSlides() {
    //Init Controller
    controller = new ScrollMagic.Controller();
    //Select some things
    const sliders = document.querySelectorAll(".wrap-container");
    const nav = document.querySelector("nav");
    //Loop over each sllide
    sliders.forEach((slide, index, slides) => {
        const revealImg = slide.querySelector(".reveal-img");
        const img = slide.querySelector("img");
        const revealText = slide.querySelector(".reveal-text");
        //GSAP
        const slideTl = gsap.timeline({
            defaults: { duration: 1, ease: "power2.inOut" }
        });
        slideTl.fromTo(revealImg, { x: "0%" }, { x: "100%" });
        slideTl.fromTo(img, { scale: 2 }, { scale: 1 }, "-=1");
        slideTl.fromTo(revealText, { x: "0%" }, { x: "100%" }, "-=0.75");
        //Create Scene
        slideScene = new ScrollMagic.Scene({
            triggerElement: slide,
            triggerHook: 0.25,
            reverse: false
        })
            .setTween(slideTl)
            // .addIndicators({
            //   colorStart: "white",
            //   colorTrigger: "white",
            //   name: "slide"
            // })
            .addTo(controller);
    });
 
}
      
      animateSlides();>

 

See the Pen LYRzBWZ by Vasanthsteel91 (@Vasanthsteel91) on CodePen

Link to comment
Share on other sites

Thank you very much @ZachSaucier, I am able to create my first animation using scroll trigger.

 

I have created another new scroll trigger. Animation is working fine but i am facing one issue. While scrolling down, i am able to see white border line over the image while animation is running.

 

To view the border line appearing over the image, i have increased the duration of animation in the codepen.

 

I have attached an image and my new code pen. can you please  help me in fixing this issue?

 

 

 

 

 

 

 

white line appearing over the top and bottom of the img-min.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...