Jump to content
Search Community

How to tween an element from its current position? The cleanest way.

venn test
Moderator Tag

Go to solution Solved by Dipscom,

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

A quick and seemingly simple question but I can't seem to find a better way to do this.

 

I wanted my elementA to tween space * 2 to the left of its current position with space being 256px.

However what is the cleaner way to do something like that?

 

x: "-=" + space*2 seems complex.

var space = 256;
TweenMax.to(elementA, 3, {x: "-="+space*2});

I could do something like this in ES6

`-=${space*2}` 

but still looks complex.

 

Thanks,
Venn.

Link to comment
Share on other sites

  • Solution

Well, if your requirement is to have a variable and use its value doubled, I am not aware of any other "less complex" way, save of creating a second variable...

var space = 256;
var doublespace = "-=" + space * 2;
TweenMax.to(elementA, 3, {x:doublespace});

Ultimately, you need to specify what the tween needs to do...

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