Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
beliy333

Adding timeScale to timeline.reverse()

Recommended Posts

Is it possible to add timeScale when playing a timeline with this method:?

timeline.reverse()

I'm running play timeline within a 'if scroll is this' loop and would like to reverse the timeline with faster speed on the 'else' statement like this:

if (scrollTop < 64) {
        timeline.play();
} 

else {
        timeline.reverse();
}

Thanks for your time.

Yan

See the Pen pgWZed?editors=001 by anon (@anon) on CodePen

Link to comment
Share on other sites

Hi beliy333  :),

 

You can just do something like this:

      if (distance < 64) {
        timeline.play().timeScale(1);
      } else {
        timeline.reverse().timeScale(3);
      }

Obviously, you can enter any timeScale value you like. Hopefully this helps.

 

:)

  • Like 4
Link to comment
Share on other sites

Oh well that's just too simple! ;)

 

Expanding on the question–do you see anything wrong with using either of those calls within my 'requestAnimationFrame' loop? I mean am I loading up the browser heavily by making it run those calls on repeat? Or is that a common practice when you're triggering events by scroll position and I shouldn't worry about it?

 

Thanks,

Yan

Link to comment
Share on other sites

Personally, I use Scroll Magic for all my scroll triggered animations so I'm not sure about common or best practices.

 

I've only played with requestAnimationFrame, but never used it in the wild for a scroll triggered animation so I'll let someone a bit more experienced with it give you that part of the answer.

 

:)

  • Like 1
Link to comment
Share on other sites

Check out this recent thread about scrolling.

http://greensock.com/forums/topic/13514-reaching-tweenmax-from-local-scope/?hl=scroll#entry56483

 

You're doing that for the most part using rAF, although you're still running logic on every tick (calculating the scroll distance). So here's your example using GSAP's ticker and a flag. The function only gets called if a scroll happened.

See the Pen bEojxr?editors=001 by osublake (@osublake) 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.
×