Jump to content
Search Community

Keep the same unit that the one define in the tween

poolboy test
Moderator Tag

Go to solution Solved by Diaco,

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

Hello,

 

As you can see in the reduce test case, if I tween the width of a div from no value to '100vw', the new value is set to '100vw'.

var div2 = document.getElementById('div2');
TweenMax.set(div2, {height: '100vw', onComplete:function(){
  div2.innerHTML = div2.style.height; // 100vw
}});

But if the value was already set in css (with the same unit), then the new one is calculate in px :


#div {
  height: 20vw;
}
var div = document.getElementById('div');
TweenMax.set(div, {height: '100vw', onComplete:function(){
  div.innerHTML = div.style.height; // ex: 1920px
}});

Is it by design ? Can I force the value to be set in the wanted unit ?

 

In my real world case, I tween the value this way

TweenMax.to('.skill', 1, {height: '4vw', width: '16vw');

I understand the need to use pixel for the tween calcul so I was hoping to be able to do this this way to re-set my value in viewport unit :

TweenMax.to('.skill', 1, {height: '4vw', width: '16vw', onComplete: function(){
            TweenMax.set('.skill', {height: '4vw', width: '16vw'});
});

But as the test case shows, it doesn't seems to work this way either.

 

 

Thanks for your time

See the Pen BovbYq by poolboy (@poolboy) on CodePen

Link to comment
Share on other sites

  • 4 weeks 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.
×
×
  • Create New...