Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
CityLights

ScrollTrigger fullpage sections: section change on resize

Go to solution Solved by ZachSaucier,

Recommended Posts

Reproduction steps:

1. Open the official demo attached in a new window

2. Scroll to the orange section saying "TWO"
2. Resize the window a significant amount

After the resize and refresh complete, ScrollTrigger will snap to a section different than the one prior to the resize.

What's an elegant way to fix this?

 

See the Pen KKpLdWW by GreenSock (@GreenSock) on CodePen

Link to comment
Share on other sites

  • Solution

Hey CityLights and welcome to the GreenSock forums.

 

To fix this you'll need to record which section is snapped to each time that it snaps. Then on refresh you should set the scroll position to the value it needs to be to have that section at the top of the viewport.

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

On 12/11/2020 at 2:33 PM, ZachSaucier said:

Hey CityLights and welcome to the GreenSock forums.

 

To fix this you'll need to record which section is snapped to each time that it snaps. Then on refresh you should set the scroll position to the value it needs to be to have that section at the top of the viewport.


Thanks for the simple scenario-specific solution which leverages the snapping sections. How would you go about this if there was no snapping behavior and the user could stop their scroll position at intermediate points between the sections?

Link to comment
Share on other sites

11 minutes ago, CityLights said:

How would you go about this if there was no snapping behavior and the user could stop their scroll position at intermediate points between the sections?

You could use the progress of the ScrollTrigger to do similar calculations. 

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