Antdev Posted April 23, 2022 Share Posted April 23, 2022 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 1 Link to comment Share on other sites More sharing options...
Solution Antdev Posted April 23, 2022 Author Solution Share Posted April 23, 2022 Doh! If I put my glasses on and read the documentation I would have read this:To use a variable in a relative way, simply add the "+=" or "-=" prefix, like {x: "+=" + yourVariable}. See the Pen vYpMzzj by antdev (@antdev) on CodePen Link to comment Share on other sites More sharing options...
Cassie Posted April 23, 2022 Share Posted April 23, 2022 Yep, just JS. No GSAP specific magic here! You can also use a template literal like so - `+=${variable}` Glad you got it fixed! 1 Link to comment Share on other sites More sharing options...
Antdev Posted April 23, 2022 Author Share Posted April 23, 2022 Thanks Cassie, that is useful to know about the template literal too. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now