Jump to content
Search Community

ScrollTrigger snap inertia

iDad5 test
Moderator Tag

Recommended Posts

After I humiliated myself last time I'm actually reluctant to as another dumb question, but I can't help myself... 
(I will build a CodePen if necessary, but my question should be understandable without one I think.)

 

  • I have a scrollTrigger that snaps to labels.
  • It is created at its starting position (scroll() = 0)
  • I want to scroll it to a position of one of the labels (lets say 500px);
  • when I do this with scrollTrigger.scroll(500) the scrollTrigger runs through all label to the end of time(line)

 

Reason: inertia (defaults to true, and setting scroll to 500 in zero seconds accounts for a great amount of inertia - I guess)

 

When I create the scrollTrigger with snap{inertia:false} the scrollTrigger scrolls to 500 and stops. BINGO

 

BUT: I would prefer the behavior for the user scrolling with inertia - feels a lot better most of the times.

 

QUESTION: Is there a way to change the snap - inertia value after creation of a scrollTrigger? (I cannot find it in the docs)

Link to comment
Share on other sites

Thank you @OSUblake, I tired that, but within a scrollTrigger with inertia enabled it does not make a difference.  When I call ScrollTrigger.scroll(500) it still overshoots to the end. 

 

I also tried to simply set the timelines position to the appropriate label  without setting the scrollTriggers scroll, that showed the panel I wanted, but when I started scrolling it jumped to the start... 

Edit: I also tried moving the timeline to the label I wanted before the creation  of the scrollTrigger, in the hope the a scrollTrigger created with an already existing animation would set its' scroll-position according to the timeline position, but that didn't work either.

 

I guess I have to do more testing and I will build a CodePen as soon as I can find the time. 

 

I do think that in the case of a scrollTrigger with snaping and inertia enabled, scrollTrigger.scroll() should, if somehow possible for once ignore inertia, as I don't see any use in the function under those circumstances - or am I missing something here?

Link to comment
Share on other sites

I think I'm going crazy....

 

here is my simplified example:

 

See the Pen rNzrqmV?editors=1111 by mdrei (@mdrei) on CodePen

 

It works as expected with inertia and without.

 

I recreated all relevant things exactly as I do in my project. In my project however the setup results in overshooting as soon as scrollTrigger->snap-> inertia is enabled, is works as expected if I disable inertia. (which I'd prefer not to do)

 

Of course in my project I do the whole thing after resizing but as i rebuild more or less everything at a resize, it should not make a big difference, I will have to make my pen a somewhat more complex to be sure...

 

 

 

 

Link to comment
Share on other sites

I might not go totally bonkers..
here is my CodePen, that is reproducing the issue...

 

See the Pen bGoVpgE?editors=1111 by mdrei (@mdrei) on CodePen

 

How to reproduce:

Scroll to any panes other than 0.

Resize

See the situation being restored to the right panel.

 

In line 69 comment out "inertia=false"

try again, and you will see the drop to the end of time(line)

Link to comment
Share on other sites

Is there a reason you don't want to set inertia: false? 

 

I assume the behavior is due to the fact that resizing would cause the scroll progress to be at a very different value quickly, thus inertia would pick that up as moving fast. I've been toying with the idea of just eliminating inertia altogether because in practical usage I don't think it's terribly helpful since it must wait until scrolling stops anyway before kicking in the snapping. 

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