Jump to content
Search Community

Scrolltrigger on leave works only first time

Kkkrxs test
Moderator Tag

Go to solution Solved by Cassie,

Recommended Posts

Hi everyone, newbie here trying to learn more about this INCREDIBLE language, I'd have a few question to ask to you GSAP GODS :)

I'm trying to animate the texts on enter with the fancy animation and onLeave disappear with a simple fade, as you can see in the codepen, it works but it has a few problems, first one is that it lowers the opacity to all the other texts below and so the other texts disappear without needing too, second problem is that when i scroll back the text doesn't appear back unless you scroll a little bit down to trigger the original animation again(thing is not needed, just making it reverse the fade would be perfect).

And there's a other thing, how can i make this animation occur on all text blocks independently so they all appear with the first animation and all disappear with the fade independently without fighting each-other, i've tried with a gsap.utils.toArray but the split text counted all the text as one and the other texts didn't do the animation on screen but finished the animation before even seeing them.

I'm getting obsessed with learning this language and would love some explanation on what I'm doing wrong with my code and how I could do it better :)

Thanks to everyone, love ya<3

See the Pen dyqqNQY by Kr1Xx (@Kr1Xx) on CodePen

Link to comment
Share on other sites

  • Solution

Heya. glad you're having fun! 

So the main thing to get right here is to get used to looping around elements and selecting the correct children within that loop

Here - I've looped around the 'blocks' and inside that loop I'm grabbing the scoped children with block.querySelector("...");

Then we don't end up duplicating code and getting all messy.

See the Pen eYLPvqN?editors=0011 by GreenSock (@GreenSock) on CodePen



Does this help?

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