Jump to content
Search Community

ScrollTrigger swup wrong starting points

adamo test
Moderator Tag

Go to solution Solved by adamo,

Recommended Posts

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

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: 

 

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

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

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

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!

  • Thanks 1
Link to comment
Share on other sites

@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 image.thumb.png.2d1aea54f2b55df712161dcfda304fa4.png

When moving to other page and returning to products the text is gone.

image.thumb.png.7982b42ac6a33c65055b65270ab80eb7.png

So the investigation continues

Edited by adamo
Added new discovery
Link to comment
Share on other sites

  • Solution

OK so the solution was easy :) Just refresh all triggers before the page leaves 

 

    swup.hooks.on("visit:start", () => {
        ScrollTrigger.getAll().forEach((t) => t.kill(false));
        ScrollTrigger.refresh();
    });

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