Jump to content
Search Community

How to get a new random number every time the time line finishes?

Sowjanya test
Moderator Tag

Go to solution Solved by akapowl,

Recommended Posts

I want a new random number every time the timeline restarts, here is the code:

 

gsap.registerPlugin(CustomEase, CustomWiggle);

let tl = gsap.timeline();

CustomBounce.create("bounce", {
  strength: 2,
  squash: .1,
});

tl.to(".box", 3, {
  x: 'random(-200, 200)',
  y: 'random(-200, 195)',
  ease: "bounce",
  onComplete: tl.restart()
})


 

See the Pen VwMeJZR by sowg (@sowg) on CodePen

Link to comment
Share on other sites

  • Solution

Hello @Sowjanya

 

You could either invalidate() your tl before you play it again ...

 

See the Pen NWaNGYg by akapowl (@akapowl) on CodePen

 

... or use repeats and set repeatRefresh: true.

 

See the Pen zYEqvWM by akapowl (@akapowl) on CodePen

 

 

 

If it always starting start from the center again is what you're going for, I guess you will have to use a fromTo tween then, though.

Hope that helps

 

  • Like 3
  • Thanks 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...