Jump to content
Search Community

Animating REM and EM units unexpected behavior

DanTheProgrammerMan
Moderator Tag

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

DanTheProgrammerMan
Posted

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.

Posted

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
DanTheProgrammerMan
Posted

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

Posted

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.

DanTheProgrammerMan
Posted

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.

Posted

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
Posted

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. 

  • 1 month later...
Posted

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

  • 1 month later...
  • 4 years later...
Posted

+1 for full rem support ?, I just spent an hour and a half trying to figure out why my animation did not look right only to find out it was related to use rem.

ZachSaucier
Posted
7 minutes ago, InTheOne said:

+1 for full rem support ?, I just spent an hour and a half trying to figure out why my animation did not look right only to find out it was related to use rem.

rem units should be supported for the most part at least: 

See the Pen WNvMyeb by GreenSock (@GreenSock) on CodePen.

 

What situation are they not working in? Can you provide a minimal demo?

  • Like 1
Posted

Ah, I was using ".5rem" instead of "0.5rem" which was actually causing the problem.

ZachSaucier
Posted
3 minutes ago, InTheOne said:

I was using ".5rem" instead of "0.5rem" which was actually causing the problem.

Hmm. That still works in the demo above. Any idea how to reproduce the error?

Posted

Hi, sorry for the slow responce. This issue was that I did not have a 0 in front of my .5rem. When I added that it solved the issue. 

ZachSaucier
Posted
2 minutes ago, InTheOne said:

This issue was that I did not have a 0 in front of my .5rem. When I added that it solved the issue. 

Right but I'm saying that if I leave out the 0 in front in the demo above it doesn't reproduce the issue. So do you know of a way to reproduce the issue in CodePen?

Posted

Oh, no that fixed the issue for me in my application. I'm not sure what would be different about my setup to where I needed the 0 for it to work.

  • Thanks 1

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