Jump to content
Search Community

Change tween duration while its tweening

Michael71
Moderator Tag

Go to solution Solved by PointC,

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

Posted

Hey guys, long time since I've been here.

 

How can I change the duration of a tween while it is tweening? So I have this:

 

 TweenMax.to(".masked", 10, {"background-position": "0px 100%"});

And I want while this is playing, to dynamically increase the duration of it, or lessen it.

See the Pen jmNQBp by netgfx (@netgfx) on CodePen.

  • Solution
Posted

HI Michael71 :)

 

I would think changing the timeScale() would be the easiest thing to do. That's exactly what I did on my recent handwriting demo with a speed control dial.

 

See the Pen MpLVvO by PointC (@PointC) on CodePen.

 

Hopefully that helps.

 

Happy tweening.

:) 

  • Like 2
Posted

Yes exactly something like this.

Can I also get the current speed? so I can gradually decrease it? 

 

This is for a loader which I'm not sure when it will finish, so I want to keep making it go slower so it doesn't end, and when it is complete to bump it to the end.

Posted

Oh, this is for a loader. I thought there was some user interaction that was causing the change.

 

I don't have much loader knowledge, but I think you'd probably want to link the percentage of page load to the progress of the timeline in that case. 

 

Maybe someone else will jump in here with some solid advice.

 

Happy tweening.

:)

Posted

If you know only this part I'm good to go: 

 

 

Can I also get the current speed?
Posted

timeScale works as a getter or setter. You could also use progress or time which also work as getters or setters.

var t = yourTween.progress(); // gets current progress
var t = yourTween.timeScale(); // gets current timeScale
var t = yourTween.time(); //gets current time

Happy tweening.

:)

  • Like 2
Posted

FYI, duration() works as a getter or setter as well:

t.duration(newDuration); //sets
var d = t.duration(); //gets

Also, yes, you can literally tween the timeScale() using another tween:

var t = TweenLite.to(...); //your original tween
TweenLite.to(t, 1, {timeScale:0.2}); //animates the timeScale to 0.2 over the course of 1 second (slowing it down)

Making things appear to slow down can also be achieved with easing, like Power4.easeOut would start out fast and then slow to a crawl. See http://greensock.com/ease-visualizer

 

Does that help? 

  • Like 2
Posted

Yes greatly, the 

.duration()

 get/set is really useful!

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