Jump to content

Frederic Gontier

Random position to Initial position

Recommended Posts


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,


See the Pen VwvPrqQ?editors=1010 by fr3d3ric (@fr3d3ric) on CodePen

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.