Jump to content
GreenSock

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

Update tween values during animation

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

Share this post


Link to post
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 ...

Mikel

  • Like 3

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×