Mike Hart Posted July 28, 2020 Share Posted July 28, 2020 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 More sharing options...
mikel Posted July 28, 2020 Share Posted July 28, 2020 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 2 Link to comment Share on other sites More sharing options...
Mike Hart Posted July 28, 2020 Author Share Posted July 28, 2020 Thanks mikel This looks like the way forward. How can I import ScollTrigger. Im using webpack with npm and cant see any references in repo? Link to comment Share on other sites More sharing options...
mikel Posted July 28, 2020 Share Posted July 28, 2020 Hey @Mike Hart, There are many ways to get GSAP. A good way: read the docs for installation. Happy tweening ... Mikel 2 Link to comment Share on other sites More sharing options...
ZachSaucier Posted July 28, 2020 Share Posted July 28, 2020 As the demo from the batch video shows, you can do this using intersection observers. But it's easier using ScrollTrigger's .batch method 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now