Jump to content
GreenSock

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

Hiding Layers

Recommended Posts

Hi Everyone!

 

Trying to figure out how I go about hiding layers in my svg using scrolltrigger. The effect I'm trying to go for is when a user scrolls down on page a new layer is displayed at certain points/triggers (while also keeping original or first layer displayed always). However as you can see from my pen example there are certain layers I'd to hide when scroll gets to a certain trigger, right now they overlap which I kind of expected. I've been reading up on stagger  but I'm not sure how I would go about implementing with scrolltrigger. 

 

Thanks in advance!

See the Pen XWdOdvQ by phernand42 (@phernand42) on CodePen

Link to comment
Share on other sites

Hey phernand42. In general it's good to forget about ScrollTrigger (at least conceptually) until things are animating the way you want to then add ScrollTrigger.

 

So how would you do this without ScrollTrigger (i.e. logically)?

You'd want to show one layer and hide the previous one each time a section is reached.

To do that sort of thing in GSAP it probably makes sense to create a timeline for each section that fades in the new content and fades out the last content (if necessary). 

 

As for your code, you're making one of the most common ScrollTrigger mistakes: putting ScrollTriggers in timeline tweens. Doing so doesn't make much sense.

 

Here's how I'd set it up:

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

 

Side notes:

  • We highly recommend putting the duration inside of the vars parameter. Doing so allows you to use GSAP's defaults functionality which is quite handy. 
  • In general it's a good idea to use triggers for the start/end of ScrollTriggers. 
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

Ahh makes so much sense. Thanks so much for explaining this @ZachSaucier! Also thanks for link to doc, will read that a bit more :)

 

I can now see the visibility is controlled by autoAlpha within each section. 

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