Jump to content
Search Community

Update Scrolltrigger with heights change

gringo_pablo test
Moderator Tag

Go to solution Solved by ryan_labar,

Recommended Posts

Hi,

 

I'm creating a small logo animation for a client. The idea is simple: the logo is fixed on the left bottom corner of the window, and when you get to the bottom of the page, it scales up to occupy a full section.

 

The animation works, but the problem is that I have two alternative layouts on my page. The user can switch the layout by clicking a button. And the two layouts are not the same heights, so it messes the scrollTrigger... 

 

I tried adding a ScrollTrigger.refresh() each time the user clicks on the switch button, but it didn't solve the problem.

 

Any idea?

 

Thanks

See the Pen LYMKMVy by gringo_pablo (@gringo_pablo) on CodePen

Link to comment
Share on other sites

  • Solution

Hi @gringo_pablo

 

You need to call the ScrollTrigger.refresh() after the layout is changed so it can make the proper adjustments:

 

btns[0].addEventListener("click", () => {
  section1.style.display = "block";
  section2.style.display = "none";
  ScrollTrigger.refresh();
});
btns[1].addEventListener("click", () => {
  section1.style.display = "none";
  section2.style.display = "block";
  ScrollTrigger.refresh();
});

 

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