Sulochan Posted February 22 Share Posted February 22 I am just trying to implement things out but not getting animations as expected. Any help will be appreciated. There is an animation which will have a component which will scale from large to 1 , therefore used .from and then it will translate to left and be out of viewPort, thus using .to . Now as soon as this completes, I want to fire another animation of exactly similar nature but the only change is the contents inside the component. Therefore I added them in the same timeline. But now only .from animation is fired for every component and .to doesn't (at least it is not visible). I want to fire the animation of another component just after finishing the .to animation. Attaching the code if it is helpful. const t1 = gsap.timeline({ scrollTrigger: scrollTriggerOptions, }); //for o t1.from(ref1.current, { scale: 17, opacity: 0, }) .to(ref1.current, { translateX: '-100%', // opacity: 0, scrollTrigger: { trigger: ref1.current, // pin: ref1.current, start: '58% 50%', end: '60% 50%', scrub: true, markers: true, }, }) .to(refo.current, { opacity: 1, width: '15.4%', }); //for f t1.from(ref2.current, { scale: 17, opacity: 0, }) .to(ref2.current, { translateX: '-100%', // opacity: 0, scrollTrigger: { trigger: ref2.current, // pin: ref1.current, start: '58% 50%', end: '60% 50%', scrub: true, markers: true, }, }) .to(reff.current, { opacity: 1, width: '10.7%', }); //for e t1.from(ref3.current, { scale: 17, opacity: 0, }) .to(ref3.current, { translateX: '-100%', // opacity: 0, scrollTrigger: { trigger: ref3.current, // pin: ref1.current, start: '58% 50%', end: '60% 50%', scrub: true, markers: true, }, }) .to(refe.current, { opacity: 1, width: '10.7%', }); //for r t1.from(ref4.current, { scale: 17, opacity: 0, }) .to(ref4.current, { translateX: '-100%', // opacity: 0, scrollTrigger: { trigger: ref4.current, // pin: ref1.current, start: '58% 50%', end: '60% 50%', scrub: true, markers: true, }, }) .to(refr.current, { opacity: 1, width: '12.7%', }); //for t t1.from(ref5.current, { scale: 17, opacity: 0, }) .to(ref5.current, { translateX: '-100%', // opacity: 0, scrollTrigger: { trigger: ref2.current, // pin: ref1.current, start: '58% 50%', end: '60% 50%', scrub: true, markers: true, }, }) .to(reft.current, { opacity: 1, width: '11.6%', }); //for a t1.from(ref6.current, { scale: 17, opacity: 0, }) .to(ref6.current, { translateX: '-100%', // opacity: 0, scrollTrigger: { trigger: ref6.current, // pin: ref1.current, start: '58% 50%', end: '60% 50%', scrub: true, markers: true, }, }) .to(refa.current, { opacity: 1, width: '14.4%', }); //for 2 t1.from(ref7.current, { scale: 17, opacity: 0, }) .to(ref7.current, { translateX: '-100%', // opacity: 0, scrollTrigger: { trigger: ref7.current, // pin: ref1.current, start: '58% 50%', end: '60% 50%', scrub: true, markers: true, }, }) .to(refl2.current, { opacity: 1, width: '11.3%', }); //for 4 t1.from(ref8.current, { scale: 17, opacity: 0, }) .to(ref8.current, { translateX: '-100%', // opacity: 0, scrollTrigger: { trigger: ref8.current, // pin: ref1.current, start: '58% 50%', end: '60% 50%', scrub: true, markers: true, }, }) .to(refl4.current, { opacity: 1, width: '12.4%', }); Attaching the video preview . Since I have coded in react, I find it difficult to display in codepen.io .(In case anyone is able to help me with this as well ) WhatsApp Video 2024-02-22 at 18.39.10-2.mp4 Link to comment Share on other sites More sharing options...
Sulochan Posted February 22 Author Share Posted February 22 A comment. in ref7 trigger, there's a typo of ref2 which has been taken care of but still , futile. Link to comment Share on other sites More sharing options...
GSAP Helper Posted February 22 Share Posted February 22 Without a minimal demo, it's very difficult to troubleshoot; the issue could be caused by CSS, markup, a third party library, a 3rd party script, etc. Would you please provide a very simple CodePen or Stackblitz that illustrates the issue? Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. See if you can recreate the issue with as few dependancies as possible. Start minimal and then incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, at least we have a reduced test case which greatly increases your chances of getting a relevant answer. See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo: Using a framework/library like React, Vue, Next, etc.? CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: React (please read this article!) Next Svelte Sveltekit Vue Nuxt Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. ✅ Link to comment Share on other sites More sharing options...
GSAP Helper Posted February 22 Share Posted February 22 Hi there! I see you're using React - Proper cleanup is very important with frameworks, but especially with React. React 18 runs in strict mode locally by default which causes your useEffect() and useLayoutEffect() to get called TWICE. Since GSAP 3.12, we have the useGSAP() hook (the NPM package is here) that simplifies creating and cleaning up animations in React (including Next, Remix, etc). It's a drop-in replacement for useEffect()/useLayoutEffect(). All the GSAP-related objects (animations, ScrollTriggers, etc.) created while the function executes get collected and then reverted when the hook gets torn down. Here is how it works: const container = useRef(); // the root level element of your component (for scoping selector text which is optional) useGSAP(() => { // gsap code here... }, { dependencies: [endX], scope: container }); // config object offers maximum flexibility Or if you prefer, you can use the same method signature as useEffect(): useGSAP(() => { // gsap code here... }, [endX]); // simple dependency Array setup like useEffect() This pattern follows React's best practices. We strongly recommend reading the React guide we've put together at https://gsap.com/resources/React/ If you still need help, here's a React starter template that you can fork to create a minimal demo illustrating whatever issue you're running into. Post a link to your fork back here and we'd be happy to take a peek and answer any GSAP-related questions you have. Just use simple colored <div> elements in your demo; no need to recreate your whole project with client artwork, etc. The simpler the better. 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