Jump to content
Search Community

Adaptive animation with random values

tilohi8071 test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Hello,

I have an animation where several elements move synchronously to a random position. To ensure that they both receive the same random value, I generate it in onRepeat.

I want to make the animation adaptive. If you change the screen width now, you will notice how the elements "jump" to new position. To fix this, I assume that when resizing, the updateX function should use the old random value. However, for some reason, onRepeat is triggered during every tick of the resize event, and I don't understand how to determine when to update the lastRand value and when to use the old one.

See the Pen abRvKao?editors=0010 by coyibe2003 (@coyibe2003) on CodePen

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...