Jump to content
Search Community

Stagger gets ignored when fired by Intersection Observer

Mike Hart test
Moderator Tag

Recommended Posts

Hi there, hope you can help.

 

Im using GSAP3 latest version.

 

For some reason the stagger property gets ignored when used in the js interesection observer api.  Works fine on its own.

 

// on its own, stagger works fine

 gsap.fromTo(".card", { x: '100%' } , { stagger: 0.5, x: 0,  duration: 2, ease: "power2.out" });

 

// not when called with js observer


              const options = {
                rootMargin: "0px",
                threshold: 0
              };


              const moveup = new IntersectionObserver(entries => {

                entries.forEach(entry => {

                  
                  if (entry.intersectionRatio > 0)  {
                      console.log(entry.ta);
                   

                    // the fromTo gets fired but not the stagger

                    gsap.fromTo(entry.target, { x: '100%' } , { stagger: 0.5, x: 0,  duration: 2, ease: "power2.out" });
                    moveup.unobserve(entry.target);
                  }

                });
              }, options);
       
              const targetElements = document.querySelectorAll(".card");


              for (let element of targetElements) {
                  moveup.observe(element);
              }

 

 

thanks in advance.

 

 

Link to comment
Share on other sites

Hey @Mike Hart,

 

Welcome to the GreenSock Forum.

 

Normally, each ScrollTrigger will fire its callbacks (onEnter, onLeave, etc.) immediately when they occur but what if you want to coordinate an animation (like with staggers) of ALL the elements that fired a similar callback around the same time? That could get awkward to do manually. Same with IntersectionObserver

 

So check out ScrollTrigger.batch().

 

Happy scrolling ...

Mikel

 

 

  • Like 2
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...