Jump to content
Search Community

ScrollTrigger container f rom right to left above text

gikall test
Moderator Tag

Recommended Posts

Hello guys,

 

I am newbie to GSAP and a little confused. 

In the above codepen I want to achieve something like the example of United Sodas scrolling section.

But I have only 4 elements to the right.. and final result I want at the middle of the right section i.e. at the end of the third photo to scrolling down and not to lose the boxes on the left.

 

Thanks in advance!

See the Pen zYadqVX by gionic (@gionic) on CodePen

Link to comment
Share on other sites

Hi @gikall welcome to the forum!

 

There are a few things I personally like to do when working with GSAP (and ScrollTrigger). Frist off I never animate the element that is also my trigger, in this example it's fine, but this will cause problems someday, so I advise you to never do it.  Next to that I like to start with a timeline, with this you get so much more control and it will become easier to add tweens to something. In most cases the .from() tween is easier to work with, because if you layout your elements like you want them to be when the animation is done you don't have to do any fancy calculations to get them to the point you want. 

 

So lets say you want your animation to be done showing 2.5 cans. I like my CSS to be at the point I want them to stop, so this is what my CSS would look like. 

 

See the Pen PoaKzEQ?editors=0100 by mvaneijgen (@mvaneijgen) on CodePen

 

The best thing to do with ScrollTrigger 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. So here I just focus on the animation, I've disabled ScrollTrigger, this also shows you the power of a timeline, because it will be trivial this way to have the text also animate in.

 

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

 

And when I'm happy with all that I turn ScrollTrigger on and take it from there. Another thing, I would not have classes and ids with the same name, this can get really confusing really fast. You have two different elements called scroller-scene, but one is a class and the other an id. Hope it helps and happy tweening! 

 

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

  • Like 2
Link to comment
Share on other sites

Have you seen my comment about the position parameter  in the code? This is a really powerful feature and I encourage you to take a look at the docs. 

 

Right now you have two tweens, that start at the same time, animate the same element, one moves your cans .form() and to other .to() I would remove one of the tweens, your last tween is now winning and I don't know what you want this one to do. 

 

And again, the best thing to do with ScrollTrigger 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.

Link to comment
Share on other sites

6 minutes ago, mvaneijgen said:

What are you confused about? You want don't want the text to tween, fine removed that form the code. Then you're done right? 

 

 

 

Yes but in your example the #scroller-wrapper  continues to go down and down and down. I want after the third "can" to continue to the bottom section, and not to show the #scroller-wrapper all over the time.

 

Here is the problem end: () => "+=" + wrapper.offsetWidth

Link to comment
Share on other sites

If that is your problem, why not remove it? The default of end is end: "bottom top" and this usually just works.

 

See the Pen RwJZpje by mvaneijgen (@mvaneijgen) on CodePen

 

I'm not 100% certain what your issue is at the moment, could you maybe explain your issue as follows:

  • A clear description of the expected result - "I am expecting the purple div to spin 360degrees"
  • A clear description of the issue -  "the purple div only spins 90deg"
  • A list of steps for someone else to recreate the issue - "Open the demo on mobile in IOS safari and scroll down to the grey container" 
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...