Jump to content
Search Community

Stacking cards, how do I stop the animation earlier?

MikeS test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

The animation works fine, but I wanted them to take a bit longer and have multiple animations play at the same time.
To achieve this I set scrollTrigger.end to 'bottom -1000px', doing so, the animations will overlap and will be a lot slower.

 

However, the animation is now overflowing on the other content.

I understand why it happens, but I am unsure as to what other approach I should use to not have this issue?

Ideally, the the pins get removed when we reach the bottom of the container, but again, I am unsure how to achieve this.

Any help is greatly appreciated!

See the Pen xxaqQjV by mikesnoeren (@mikesnoeren) on CodePen

Link to comment
Share on other sites

Hi @MikeS welcome to the forum! 

 

Instead of making a ScrollTrigger for each card why not wrap them in a container and add a ScrollTrigger to the whole container and animate all the cards within that. It seems like you want all the cards to interact with each other so having them be part of the same animation seems like a much easier approach, because then you just have to manage one start and one end trigger and you can use the same tween by just using a stagger on it, see the Stagger docs

 

Take a look at this video from the Greenock YouTube channel. It kinda deals with the same idea, but in reverse! Hope it helps and happy tweening! 

 

 

Link to comment
Share on other sites

  • Solution

Sure. CSS is really important when working with GSAP. Personally I like positioning my elements where they should end up when the animation is done! So in your CSS I've used CSS Grid to have all the elements stack on top of each other. 

 

When working with ScrollTrigger the best thing to do with it is to remove it! This seems counter intuitive, but ScrollTrigger is just animating something on scroll, so just focus on the animation at first and only when you're happy with the animation add ScrollTrigger back in. That is what I've done with the below pen. Because I've moved to a timeline it's easy just to toggle ScrollTrigger on and off while working to get a better understanding what the animation is doing. 

 

I've placed some comments within your code to describe what certain parts of the code are doing. Hope it helps and happy tweening! 

 

See the Pen jOvBXWN?editors=0010 by mvaneijgen (@mvaneijgen) on CodePen

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