Jump to content
Search Community

Update ScrollTrigger on window resize

VecchiaPrugna test
Moderator Tag

Recommended Posts

I created a custom scrollbar with this setup:
- lenis for smooth scroll

- a few lines of css to hide default scrollbar
- GSAP scrollTrigger to sync the thumb position with the scroll position

- GSAP Draggable to enable scroll by dragging the thumb

 

It works great, but if I resize the window (so that the height changes) it does not work anymore.

My idea was to kill the scrollTween and the reinitiate it on window resize, but it doesn't seem to work. Sometimes it does on first resize but then if you keep resizing it starts messing up.
Only thing that works is that the thumb height is properly resized 

 

IMPORTANT: To see the problem I'm trying to point, open the codepen and try resizing the window a couple times, then try to scroll up and down the whole page

See the Pen QWRywKp by ykvdnykw-the-bold (@ykvdnykw-the-bold) on CodePen

Link to comment
Share on other sites

I don't have much time right now, but I very quickly made an edit: 

See the Pen gOJPZqM?editors=0010 by GreenSock (@GreenSock) on CodePen

 

You were just killing the scrollTween and creating a whole new one, but you forgot to reset the position. So, for example, if you resized the window after the scrollbar was already 500px down from the top, you'd be creating the new scrollTween from that [new] position instead of from 0. 

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