Jump to content
Search Community

Add 'image reveal' effect on scroll

archimedo test
Moderator Tag

Recommended Posts

Hi,

I'm exploring the possibilities of GSAP + scroll trigger and I'd like to build a grid gallery page where images come on view with a fade-in effect (which I was able to achieve with 'gsap.from' function).

I'm also trying to trigger this animation only when images come into the viewport so that If I have a long list, the effect will apply only on elements visible in the screen.

For that I used a scrolltrigger function, with the image container as trigger and start at "top bottom" but unfortunately it seems that I'm missing something here because the effect is still applied to all images on the page at once.

Can you help me figuring out how to fix this?

Thanks!

See the Pen BabaEga by aieio (@aieio) on CodePen

Link to comment
Share on other sites

A couple things -  

  1. Your demo was missing the ScrollTrigger plugin.
  2. You're triggering all animations with the same class at the same time.

You can loop through and create a trigger for each image like this

See the Pen 06cc4d1f848523ff0a28fb6151664226 by PointC (@PointC) on CodePen

 

The problem with that is all the pictures in the same row animate at the same time. That may be what you want, but quite often you want to stagger the targets in each row. 

 

That's the perfect use case for batch.

See the Pen 34fbf1d6bf627411758c1cac157f0d20 by PointC (@PointC) on CodePen

 

More info about batch.

https://gsap.com/docs/v3/Plugins/ScrollTrigger/static.batch()/

 

Hopefully that helps. Happy tweening.

:)

 

  • Like 2
Link to comment
Share on other sites

thank you so much for your help!

I think the batch can work for my case, however I was noticing in your example that only the first row is shown when the page loads even though the second row would be already visible on the viewport.

is there a way to trigger the animation when items enter the view port? so for instance if there's a long vertical screen the first 3/4rows will be already triggered without even scrolling

Link to comment
Share on other sites

On 12/24/2023 at 2:31 PM, archimedo said:

I think the batch can work for my case, however I was noticing in your example that only the first row is shown when the page loads even though the second row would be already visible on the viewport.

is there a way to trigger the animation when items enter the view port?

Sure, just change the start

// old
start: "top center"

// new
start: "top bottom"

 

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