Jump to content
Search Community

slow down animation on repeat

deanpien test
Moderator Tag

Go to solution Solved by Diaco,

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Thanks for the demo.

 

One option is to call an outside function onRepeat to tween the timeScale

 

http://codepen.io/GreenSock/pen/pJEGWb?editors=001

 

But I would probably do something like this:

 

var part1 = new TimelineMax()


part1.to("#greenBox", 1, {x:550, rotation:360})
  .to("#purpleBox", 1, {x:550, rotation:-360}, "+=0.2")


var main = new TimelineMax();
main.add(part1.tweenFromTo(0, part1.duration()))
    .add(part1.tweenFromTo(0, part1.duration()).timeScale(2))
    .add(part1.tweenFromTo(0, part1.duration()).timeScale(4))


$("#restart").click(function () {
        main.restart();
    });

 

http://codepen.io/GreenSock/pen/rVMPGm?editors=001

 

Basically your main timeline has 3 tweens that scrub through part1's timeline at different speeds.

  • Like 2
Link to comment
Share on other sites

  • Solution

Hi deanpien  :)

 

in addition to Carl great advise , you can do like this too :

part1.to("#greenBox", 1, {x:550, rotation:360})
  .to("#purpleBox", 1, {x:550, rotation:-360}, "+=0.2")
  .add(function(){  part1.timeScale(part1.timeScale()+ 0.5) /* or part1.timeScale(part1.timeScale()*2) */ })
  • Like 3
Link to comment
Share on other sites

  • 3 years later...

Hi,

 

I'm reviving this old thread. I had the same problem, so here's a way to tween the timeScale of a timeline using TweenMax. In this way you can also set the ease for the timeScale increase/decrease or have an onComplete callback if you wish.

 

Here's a

See the Pen OaKqoq?editors=0010 by anatolbogun (@anatolbogun) on CodePen

.

 

function tweenTimeScale( opt ) {
  const { timeline, duration, from, to, onComplete, onCompleteParams, onCompleteScope } = opt
  let { ease } = opt
  if ( !ease ) { ease = Linear.easeNone }

  const timeScale = { value: from }
  TweenMax.to( timeScale, duration, { value: to, ease, onComplete, onCompleteParams, onCompleteScope } )

  var updateTimeScale = function() {
    // console.log( 'timeScale:', timeScale.value )
    timeline.timeScale( timeScale.value )

    if ( timeScale.value !== to ) {
      window.requestAnimationFrame( updateTimeScale )
    }
  }

  window.requestAnimationFrame( updateTimeScale )
}

 

Usage is quite straightforward:

const tl = TimelineMax()
tl.to( obj, 1, { rotation: 360, repeat: -1 } )
// etc.

// e.g. slow the timeline to a halt over 3 seconds and pause it at the end
tweenTimeScale( {
  timeline: tl,
  duration: 3,
  from: 1,
  to: 0,
  ease: Power2.easeOut, // optional
  onComplete: tl.pause, // optional
  onCompleteScope: tl, // optional
} )

 

  • Like 3
Link to comment
Share on other sites

Hi @OSUblake , thanks for your reply and the CodePen. I wonder why I didn't just try it with a timeScale tween in the first place. Well, I tried to tween _timeScale at some point but the result didn't look right obviously. Thanks also for some other useful suggestions in the code. I didn't know about _gsTransform , that's handy.

Link to comment
Share on other sites

4 hours ago, Anatol said:

I wonder why I didn't just try it with a timeScale tween in the first place. Well, I tried to tween _timeScale at some point but the result didn't look right obviously.

 

Yes, _timeScale is a private backing value that gets set by the .timeScale() method, so it wasn't being updated correctly. 

 

It might not be obvious, but the tween is actually calling the .timeScale() method here. It's really not documented anywhere, but you can animate function based getters/setters, which is what the .timeScale() method is. So you can animate any tween/timeline method that gets and sets a number value, like .progress() and .time().

 

TweenLite.to(myTimeline, duration, {
  timeScale: 0 // calls myTimeline.timeScale() method
});

 

 

An old demo showing different different ways to create getters/setters that GSAP can use. Box 4 is how most GSAP methods work.

 

See the Pen 6d42dd35adee8af8ce9c1bcf3f2e6cb2 by osublake (@osublake) on CodePen

 

 

 

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