Jump to content


Update tween values during animation

Moderator Tag

Recommended Posts

I am having trouble getting this to behave. I have an animation that is occurring inside of an element that is also being animated (or changed). The issue is that when the outer element changes size, all of the values for the inner animation are not adjusting to the new size. In the codepen you can see this by clicking the start button and then either resize the output window or click the enlarge button to enlarge the outer div. How do you solve this. How do you tell the tween to pay attention to the values if that change? Thanks.

See the Pen vYEWOPq?editors=1111 by Wcomp (@Wcomp) on CodePen

Link to comment
Share on other sites

Hey @wcomp,


Let GSAP do all transform jobs: clearer and more practical


See the Pen vYEWNPy by mikeK (@mikeK) on CodePen


Info to transforms and transformOrigin e.g.: here.


Happy tweening ...


  • Like 3
Link to comment
Share on other sites

Hey wcomp,


A few notes first:

  • https://s3-us-west-2.amazonaws.com/s.cdpn.io/16327/TweenMax-latest-beta.js is actually a really old version of GSAP. We highly recommend that you use the latest version of GSAP: 3.0.4
  • GSAP 3 has a feature of timelines called defaults that will save you from having to copy and past the same properties each tween.
  • GSAP 3 also has a default duration of 0.5 so you could even leave out the duration completely (if you do include it, in GSAP 3 we recommend that you put duration in the vars parameter, not as the second parameter).
  • GSAP 3 also has a shortened ease format which you could use. 
  • We highly recommend using GSAP's x, y, xPercent, and yPercent over animating a transform value. 
  • Using classes can help you keep your code much more DRY (don't repeat yourself).

Now to answer your question.

Tweens are compiled when then are created for performance reasons. So dynamic tweens don't really exist (though there are alternative methods for setting dynamic values like using GSAP's ticker in combination with .set()). 


However, in your case, you don't need dynamic values. If you don't use the transform property but instead use xPercent it will stay proportional because it will use responsive units which prevents the need for dynamic values. 


You can also greatly simplify your animation by placing the contents in an additional container and animate that container instead.


Altogether it could look something like this:

See the Pen jOEabgv?editors=0010 by GreenSock (@GreenSock) 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.