Jump to content

Search In
  • More options...
Find results that contain...
Find results in...
Mike D

Tweening a className while overriding a property in that class

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

Hi guys,


So I have a "default" class for an element that places it offscreen and ready to be animated in. I remove the "default" class in the tween which works just fine.

.myelement { left: 0px; }
.myelement.default { left: -200px }

TweenLite.to(".myelement",speed, { className: "-=default" });

Now, I have some scaling logic in place that is fired on resize. When resized, the "left" property is updated which now needs to overwrite the ".myelement" left value contained in the element's .myelement class.

TweenLite.to(".myelement",speed, { className: "-=default", left: "-300px" });

My guess is that the ".myelement" left value is overwriting the passed "left" parameter. Any suggestions on optimizing this is greatly appreciated.


 - Mike D

Link to comment
Share on other sites

Hello Mike..


Have you tried setting the left property to -300px after the class is removed, using the onComplete special property:

TweenLite.to(".myelement", speed, { className: "-=default",
                  TweenLite.set(".myelement", { left: "-300px" });

See if that helps..


If not, can you please setup a limited

See the Pen by pen (@pen) on CodePen

or jsfiddle with an example of your issue..


thx :)

  • Like 2
Link to comment
Share on other sites

I'm not certain what the effect needs to look like, but splitting it into two tweens might work too:

TweenLite.to(".myelement", speed, { className: "-=default" });

// overwrites the left tween of the className tween
TweenLite.to(".myelement", speed, { left: "-300px" });
  • 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.