TrulyNewbie Posted May 27, 2021 Share Posted May 27, 2021 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 Thanks! Link to comment Share on other sites More sharing options...
GreenSock Posted May 27, 2021 Share Posted May 27, 2021 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? 1 Link to comment Share on other sites More sharing options...
TrulyNewbie Posted May 28, 2021 Author Share Posted May 28, 2021 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 comment Share on other sites More sharing options...
GreenSock Posted May 28, 2021 Share Posted May 28, 2021 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 comment Share on other sites More sharing options...
TrulyNewbie Posted May 28, 2021 Author Share Posted May 28, 2021 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 comment Share on other sites More sharing options...
Cassie Posted May 28, 2021 Share Posted May 28, 2021 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. 6 Link to comment Share on other sites More sharing options...
TrulyNewbie Posted June 3, 2021 Author Share Posted June 3, 2021 Thank you! @Cassie 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