adamo Posted February 27 Share Posted February 27 Hi. I've recently encountered a problem where the scrolltrigger animation starts at a wrong place when transition is used (swup). The initial animation starting points are ok the website address is https://cedo.depcore.agency and the You can see the problem on this video https://www.dropbox.com/scl/fi/ckuvcm670lpkedun5vgna/scrolltrigger.webm?rlkey=shs49mb09k59f61plmcq7ys8t&dl=0 Not sure what has cause it and how to fix it. Link to comment Share on other sites More sharing options...
GSAP Helper Posted February 27 Share Posted February 27 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...
adamo Posted February 27 Author Share Posted February 27 I've replicated it as much as i could the problem as far as i can tell is that by scrolling up the first animation isn't reversing (leaving the trash bag) See the Pen OJGLXZV by depcore (@depcore) on CodePen Link to comment Share on other sites More sharing options...
Rodrigo Posted February 27 Share Posted February 27 Hi, Seems to me that you're using some type of framework like Vue, Svelte, React, etc. or perhaps a transition library like Barba? This could stem from the fact that when you change pages you're not cleaning up/reverting the existing ScrollTrigger instance. In your video when you navigate to About you can see that while the transition is happening the markers are still there, then you go back to the main index route and you get a duplicated set of markers. On top of that it seems that somehow you're waiting for the content to load but when you go back the height of the hero section is not taking into account. You can see the markers at 12 seconds in your video are basically at the bottom of the nav bar element, which tells me that when ScrollTrigger does it's calculations, the element with the trash bag is right below that element and the hero is either not rendered yet or it doesn't have it's final height. That's all I can get from the live site and the video since your demo doesn't replicate the issue. Hopefully this helps. Happy Tweening! Link to comment Share on other sites More sharing options...
adamo Posted February 28 Author Share Posted February 28 Yep I'm using swup, that's why it was hard to replicate this using codepen. I've notices another thing that when scrolling up very fast the enter animation isn't reverting. Maybe it has to do with this (on the attached code pen you can see this). You mentioned resetting Scrolltrigger do you mean with thew ScrollTrigger.refresh() method? Link to comment Share on other sites More sharing options...
Rodrigo Posted February 28 Share Posted February 28 Hi, 6 hours ago, adamo said: You mentioned resetting Scrolltrigger do you mean with thew ScrollTrigger.refresh() method? Nope, that's done with GSAP Context: https://gsap.com/docs/v3/GSAP/gsap.context() You can create your GSAP and ScrollTrigger instances inside a GSAP Context instance and then you can revert it, that will revert all the instances inside it which should help in this case. const ctx = gsap.context(() => { const tl = gsap.timeline({ scrollTrigger: { ... }, }); }); // Later in your code when you change routes ctx.revert(); // <- Cleanup! every GSAP instance is removed I'm not familiar at all with SWUP but it seems that is a library for page transitions like Barba. That should have some specific hooks in it's API like when the previous page animation is completed, that would be the moment to revert the GSAP Context Instance. 6 hours ago, adamo said: I've notices another thing that when scrolling up very fast the enter animation isn't reverting. Maybe it has to do with this (on the attached code pen you can see this) I'm not 100% sure of what you mean with this, can you be more specific about what should happen and what is actually happening right now? Happy Tweening! 1 Link to comment Share on other sites More sharing options...
adamo Posted February 28 Author Share Posted February 28 (edited) @Rodrigo Thank you for the tips I'll try the context part tomorrow and hopefully this will help. As for the Quote I've notices another thing that when scrolling up very fast the enter animation isn't reverting. Maybe it has to do with this (on the attached code pen you can see this) After double checking this occurs only on the development environment so hopefully it'll stay this way Update: I've notices that this is not the only issue on the site so it has to do mostly with swup because on the products page first load this part shows correctly When moving to other page and returning to products the text is gone. So the investigation continues Edited February 29 by adamo Added new discovery Link to comment Share on other sites More sharing options...
Solution adamo Posted March 1 Author Solution Share Posted March 1 OK so the solution was easy Just kill all triggers before visit starts and refresh them on end swup.hooks.on("visit:start", () => { ScrollTrigger.getAll().forEach((t) => t.kill()); }); swup.hooks.on("visit:end", () => { ScrollTrigger.refresh(); }); 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