Jump to content
GreenSock

DanTheProgrammerMan

Animating REM and EM units unexpected behavior

Recommended Posts

Hello,

 

I am trying to animate using rem units and am encountering unexpected behavior. In short, I'm doing this tween:

 

    TweenLite.to("#blue-circle-1", 1.2, {
      delay: 0.2,
      left: '-1rem',
      top: '4rem',
      ease: Elastic.easeOut
    });
 
But the blue circle actually ends up at top:0px, left:0px instead of the expected left: -1rem, top: 4rem. This is demonstrated in the codepen . Interestingly, if I run the same exact Tween again, after the first failed Tween, it will go to the proper position.
 
In addition, when trying to do the same thing with EM units, as seen at this codepen

See the Pen zGwvPd by anon (@anon) on CodePen

,
we see that the element does reach the correct position of  left: -1rem, top: 4rem, but the animation itself is not fluid, it looks like it has teleported. 
 
And finally, the same animation works perfectly using the jquery animate function, doing what I'd expect it to do. See at this codepen:

See the Pen bdWVKN by anon (@anon) on CodePen

 
Can anyone explain why this is happening, or is this a bug?
 
Thanks!

See the Pen mJmeMa by anon (@anon) on CodePen

Link to comment
Share on other sites

This happens with special units because the computed style is in px. If you set the start values before tweening, it should work.

 

See the Pen GJmoJR by osublake (@osublake) on CodePen

  • Like 3
Link to comment
Share on other sites

Thanks for the response, that seems to work for EM,

 

but for REM, using the set method sets it to top:0, left:0 still. In this pen I simply set the position to be exactly the same as its starting position, and yet we see it move to top:0px left:0px. What's up with that? 

 

See the Pen pJPgyr by anon (@anon) on CodePen

 

Thanks

Link to comment
Share on other sites

I don't know if its even recognizing "rem" as a unit. I think Jack will probably have to answer that, as I really couldn't find an answer by just skimming through the source code.

 

I don't know of an easy fix for you at the moment. You might just have to convert the units manually. For what its worth, I ran into a similar problem before, and raised an issue on GitHub.

Link to comment
Share on other sites

Hmm it's too bad. For this particular circumstance I need to go back to using jquery animate (never thought I'd say that) I guess as it is able to properly handle REM units.

Link to comment
Share on other sites

The only other thing I can think of is to tween an object and update the css in the onUpdate callback or by using a getter/setter.

 

See the Pen doWGQP by osublake (@osublake) on CodePen

  • Like 2
Link to comment
Share on other sites

Sorry about the em/rem hassles. We will consider adding support in a future CSSPlugin update, but this is the first request we've had and we have a number of high priority features in the works right now. 

Link to comment
Share on other sites

  • 1 month later...

I second the request for REM support, it's my favorite unit and an absolute joy to use to make responsive websites :)

Link to comment
Share on other sites

  • 1 month later...

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