Jump to content
Search Community

ScrollSmoother effects not working after route change in Nuxt.js

nicolaseielll test
Moderator Tag

Recommended Posts

Hello guys!

 

First of all I really appreciate your help here on the GreenSock Forum! It really helps me out!

 

The question:

 

I have a scrollSmoother parallax effect set to few images on the front page but it stops working after I navigate to another page and back. I have tried this.$ScrollSmoother.refresh() but it seems to have no effect on the animation. My site is built on Nuxt.js and my scrollSmoother is located in the layouts of the project.

 

This is my scrollSmoother object and the parallax effect:

 

image.png.1014c49133715f653dfbfd6a4691ecaa.png

Link to comment
Share on other sites

I tried but it seems that I don't have enough experience to work with that setup. It is way more complicated than mine and I could not understand what is going on in there. The code that I sent in a screenshot is all I have to set up the scrollSmoother & parallax effect so there's nothing more to show. And I described where the code is located as well. Can you figure out anything based of it? It would be very helpful.

Link to comment
Share on other sites

Just copy and paste what have you. The only difference in the CodeSandbox is that you import from gsap-trial instead of gsap. Everything else should match up with your local environment. There is no need to use that nuxt gsap module, nor do we officially support using it.

 

import { gsap } from "gsap-trial";
import { ScrollTrigger } from "gsap-trial/ScrollTrigger";
import { ScrollSmoother } from "gsap-trial/ScrollSmoother";

mounted() {
  gsap.registerPlugin(ScrollTrigger, ScrollSmoother);
  
  ScrollSmoother.create({
    ...
  })
}

 

Link to comment
Share on other sites

I'll post back later with a component for ScrollSmoother that might make this easier for you.

 

One thing to keep in mind for effects is they are ScrollTrigger instances, so you should kill them when navigating to a new page. And to get ScrollSmoother to parse data attributes, you can run this on after navigating to a new page. That will search the DOM for any elements that have a data-speed or data-lag attribute, and create an effect.

 

smoother.effects("[data-speed], [data-lag]", {});

 

  • Like 1
Link to comment
Share on other sites

Is there a way I could run this inside the page component because I have my scrollSmoother in the nuxt default layout so I don't have to define the smoother on every page? I tried to put that inside watch: {"route"() {}} so it would run every time a route changes inside the layout but it did not help. So is it necessary to put it in the page component for it to work?

Link to comment
Share on other sites

You can create it however you want. The demo I posted above has the ScrollSmoother in the layout page, but I'm updating in the index page, because that's where the elements are. You have to keep in mind how Vue/Nuxt works. Children are mounted before the parent, so that's why I put the observer in there to wait for the parent to mounted.

 

 

Link to comment
Share on other sites

Not sure if it's related to what you're asking, but there was a regression in 3.10.3 that could cause effects to not get triggered at the right positions if you scroll down and then resize the window. You can download an updated zip from greensock.com right now and it will have that fix in place. We'll release the official one within the next few days most likely. 

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...