Jump to content
Search Community

Scrollsmoother, method to refresh?

VikasGupta test
Moderator Tag

Go to solution Solved by OSUblake,

Recommended Posts

Hello,

Thank you for the nice plugin.

Basically I want to refresh Scrollsmoother to recalculate page height after a ajax call or any other action by JS.

I am not able to find refresh method here in docs.

 

Is that I need to kill and create every time?

 

Link to comment
Share on other sites

Hey @Blake! How would I use this in a React context?

 

Small example of what I'm trying to achieve below:

let smoother = null;

useEffect(() => {
  smoother = ScrollSmoother.create({
    smooth: 1,
    normalizeScroll: true,
    effects: true
  })
}, [smoother]);

function filterScrollUpdate() {
  smoother.refresh()
}

 

Doing this I get `TypeError: smoother.refresh is not a function`

 

Thank you!

 
  • Like 1
Link to comment
Share on other sites

5 minutes ago, OSUblake said:

There is no refresh method on the smoother instance... at least for now. 

 

And even if there was, you would have to use useRef for the smoother.

 

let smoother = useRef();

useEffect(() => {
  smoother.current = ScrollSmoother.create({
    smooth: 1,
    normalizeScroll: true,
    effects: true
  })
}, []);

 

But we'll look at adding a refresh method to the smoother. In the meantime, here's another approach to creating a ScrollSmoother using context.

 

https://codesandbox.io/s/gsap-scrollsmoother-next-js-starter-0h67eh?file=/pages/index.js

 

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