Jump to content
Search Community

Using gsaps new random feature

sirhclluk
Moderator Tag

Recommended Posts

ZachSaucier
Posted

Hey sirhclluk and welcome. 

 

It seems that you need to include the unit if you're going to use the string form:

x:"random(['0px', '100px', '200px', '500px'])"

 

I find it more intuitive to use the utils version:

gsap.utils.random([0, 100, 200, 500])

 

You could pair it with repeatRefresh for a different random value each time if you'd like:

gsap.timeline({repeat:-1, yoyo:true, repeatRefresh:true})
.to(circ_1, {x:gsap.utils.random([0, 100, 200, 500], true), ...})

 

  • Like 1
Posted

Thanks @ZachSaucier 

Yeah I didn't think about the repeat refresh. Even if mine did work, I'd never see the random change. 

Thank you

Posted

There was indeed a minor bug in GSAP that affected string-based "random()" values when the Array form was used, like "random([-100, 20, 80])". That'll be resolved in the next release which you can preview at https://assets.codepen.io/16327/gsap-latest-beta.min.js

 

Of course as @ZachSaucier mentioned, you can just use the regular gsap.utils.random() method directly instead in the meantime. ?

  • Like 3
Posted

Thanks Jack. I look forward to that one. Great work!

  • Like 1

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.
×
×
  • Create New...