Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
jimmy-a

Horizontal section. Show items with fadeIn.

Recommended Posts

Hello!

 

After the previous issue with the "scroll size" –thanks Zach for assisting me with that!– now I'm dealing with other issue (3 issues, actually).

 

1) I'm trying to make different elements appear on "fadeInUp" when they're in the viewport, or add that class if the scroll position is >= to the items position, so those items should be already visible if the user scrolls up –e.g. the user has entered the website following a link with a hash/anchor link in it and it takes them to scroll position "Y" instead of "0"–, avoiding play the transition/animation again.

 

2 ) Same goes for scrolling the horizontal scrolling; the elements inside each horizontal slide are "showing up" without applying the transition/animation.

 

3) In the same Codepen, if the element is visible (already has the "fadeInUp" class), and you switch the browser tab to another one (like Google or whatever) and then go back to the Codepen, it plays the same transition/animation again (only on the items inside the "horizontal section"), which I don't want to.  This happens even checking if the element hasClass and adding that class only if the element doesn't have that class already. 

 

Again, I'm not sure if this is the right approach for this, so any improvement is very welcomed.

See the Pen LYGOrRr by jimmyadaro (@jimmyadaro) on CodePen

Link to post
Share on other sites

Hey Jimmy.

1) isn't an issue, it's just part of your description, right? Or am I misunderstanding?

 

As for 2), it's working as you told it to: those ScrollTriggers have no idea that they're in a horizontal scrolling section so they're all firing when the first one is reached because from their perspective they all have the same vertical offset. To get it working the way you want to you'd need to add their horizontal offset to the start value. Or just use a different approach of firing them when they're in the viewport like using the intersection observer API.

 

3) appears to be because the pin-spacer is being recreated when the page is navigated back to and that causes your CSS animation to fire. If you switch out those animations to be GSAP ones (which are more powerful and better to use if you're using GSAP anyway) it fixes the issue:

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

  • Like 1
  • Thanks 1
Link to post
Share on other sites
2 minutes ago, ZachSaucier said:

Hey Jimmy.

1) isn't an issue, it's just part of your description, right? Or am I misunderstanding?

 

As for 2), it's working as you told it to: those ScrollTriggers have no idea that they're in a horizontal scrolling section so they're all firing when the first one is reached because from their perspective they all have the same vertical offset. To get it working the way you want to you'd need to add their horizontal offset to the start value. Or just use a different approach of firing them when they're in the viewport like using the intersection observer API.

 

3) appears to be because the pin-spacer is being recreated when the page is navigated back to and that causes your CSS animation to fire. If you switch out those animations to be GSAP ones (which are more powerful and better to use if you're using GSAP anyway) it fixes the issue:

 

 

 

Hi Zach!

 

1) Now using GSAP's animations seems like it doesn't do that anymore, which is great :) 

 

2) I don't get it, how do I "add their horizontal offset to the start value"? I'll check the intersection observer API tho.

 

3) Awesome, I tried something like that after publishing this post, but your coding is even better, thanks!

Link to post
Share on other sites
5 minutes ago, jimmy-a said:

how do I "add their horizontal offset to the start value"? I'll check the intersection observer API tho.

You'd need to calculate the element's offset and calculate the exact value that you need. It's the sort of thing that ScrollTrigger normally does for you. Check out how I changed the start value:

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

Link to post
Share on other sites
21 minutes ago, ZachSaucier said:

You'd need to calculate the element's offset and calculate the exact value that you need. It's the sort of thing that ScrollTrigger normally does for you. Check out how I changed the start value:

 

 

 

For some reason I do have some issues with that approach:

 

1) The elements that are not inside the .side-scrolling-wrapper element seem to not being affected by this new start() value.

 

2) Idk why or how, but it doesn't work on my real project, which is 99% similar to the Codepen's code (I use different class names but still the same structure). I'll try to debug this from my side but any idea about why this may happen would be great.

Link to post
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.

×