Share Posted April 23, 2020 Hello, I would like to set elements from an array to random x and y, move them to a new random x and y position and finally have them go back to their recorded first x and y position. The following doesn't work because there is a jump between the last two tweens: var myArray = [{x:10,y:10},{x:10,y:55},{x:10,y:100}]; var tl = gsap.timeline() tl.set(myArray,{x:"random(20,280)", y:"random(20,230)"}) tl.to(myArray,{x:"random(20,280)", y:"random(20,230)", duration:5}) tl.from(myArray,{x:"random(20,280)", y:"random(20,230)", duration:3}) How can I do that? Is there a better approach? Thank you, fred See the Pen VwvPrqQ?editors=1010 by fr3d3ric (@fr3d3ric) on CodePen Link to comment Share on other sites More sharing options...
Share Posted April 23, 2020 Hey Frederic. One option is to save a copy of the values (not references) of the original array and have GSAP animate to the copy at the end: See the Pen ExVZLvo?editors=0010 by GreenSock (@GreenSock) on CodePen 1 Link to comment Share on other sites More sharing options...
Author Share Posted April 23, 2020 Hey Zach, Thanks for your response. It works perfectly. I have also found a solution using a "reversed" timeline... kinda weird but it works: See the Pen yLYgQwy?editors=1010 by fr3d3ric (@fr3d3ric) on CodePen 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