Jump to content

Search In
  • More options...
Find results that contain...
Find results in...

Opposite of random()

Recommended Posts

Hi, I've read the docs, but I'm still unsure. What is the opposite of random() ?


I want my divs to be "yPercent:2" away from eachother



Link to post
Share on other sites

Hi @TrulyNewbie. I read your question a few times and I'm still kinda lost. Are you asking a GSAP question related to animation or are you asking a CSS question about how to set up your <div> elements to have a 2% margin? And where does "random()" tie in? 

  • Like 1
Link to post
Share on other sites

Hi, a GSAAP question I believe. So at the moment I have an animation where the divs are scattered and when they gather I want them to have a 2% margin from each other. But all divs have the same name. So I figured I’d have to do it dynamically 

Link to post
Share on other sites

Sure, if you can provide a minimal demo we'd be happy to take a peek. 


It kinda depends on your setup. I'd probably make them set up initially the way you want them with the CSS determining their layout (margin) and then you could animate to x/y of 0 from a random value. Another option is to use Flip plugin which will do all the hard work for you - simply capture the current state, put them in the state you want (you could apply a class, remove inline styles whatever) and then tell Flip to animate from the previous state. 

Link to post
Share on other sites

Thank you for your help. 

This demo gave me the code i was thinking of - 

See the Pen KVVNjy by GreenSock (@GreenSock) on CodePen


yPercent:function(index){ return index * 2},

^^^ That's what I had mind.


Thank you again!

Link to post
Share on other sites

The opposite direction maybe? Coming from random values and ended up at predefined values?

This is how I'd do it -

See the Pen YzZrEPV by GreenSock (@GreenSock) on CodePen

note, I've updated to new GSAP3 syntax and changed the CDN link too.

  • Like 6
Link to post
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.