Jump to content
Search Community

gsap.to with a variable for the amount to move

Antdev test
Moderator Tag

Go to solution Solved by Antdev,

Recommended Posts

Hello

 

Need a little help with some syntax. I want to change the x position of an element by a dynamic amount but can't get the syntax correct.

 

x:"+=variable" doesn't work, nor does x:+=variable

 

Thanks

 

Ant

 

p.s apologies for the text formatting - I could not remove it :(

 

function doThatThing() { 
  gsap.to(".square", {x:"+=100, duration:2"})
}

function doThatThingVariable() {
  const amount = 100
  gsap.to(".square", {x:"+=amount, duration:2"})
}

 

 

 

See the Pen RwxOYLQ by antdev (@antdev) on CodePen

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