Jump to content
Search Community

Why stagger new random numbers don't work?

Yusuke2223 test
Moderator Tag

Recommended Posts

So what I'm trying to do is when my stagger is done and after making it yoyo..it will change the new index of staggering..but it is not working even though I follow the stagger function is right.

 

            let rands = Math.ceil(Math.random() * (9 - 0) + 0)
            gsap.to(document.querySelectorAll(".box"), {
                delay:1,
                duration: 2,
                scale: 0.1,
                ease: "power2.inOut",
                stagger: {
                    // grid: [1,9],
                    from: rands,
                    each:0.2
                },
                repeat: -1,
                yoyo:true,
                repeatRefresh:true,
                onRepeat: () => {
                    console.log(rands)
                    rands = Math.ceil(Math.random() * (9 - 0) + 0)
                }
            });

As you can see I tried it console.log it out but it seems it changing value but the "from" is not changing the index. Did I misinform this logic? I already saw something like this 

 

but it is not working on me when I tried it. 

See the Pen wvmqpmW by jullemyth122 (@jullemyth122) on CodePen

Link to comment
Share on other sites

Hello!

I think this is due to the fact that you need to use functional values alongside repeatRefresh - e.g. x: () => rand

But some properties don't allow functional values. From the docs I can see that from takes either a string, an integer or an array - not a function. You could pull the entire tween out into a function and then make a new one each time?

Like so

See the Pen dymzdOY?editors=0010 by GreenSock (@GreenSock) on CodePen



Hope this helps.

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