Jump to content
Search Community

How to move divs/images randomly in an HTML page and bounces with the screen edges and also when they meet each other?

manumqln
Moderator Tag

Recommended Posts

Posted

I want multiple elements (images/divs) to move around the HTML page in random motion bouncing of each other and the edges of the screen. The example I have given is in GSAP2.0. Can anyone help how to do this in GSAP 3?

See the Pen vYyOmQw by manumqln (@manumqln) on CodePen.

  • manumqln changed the title to How to move divs/images randomly in an HTML page and bounces with the screen edges and also when they meet each other?
Posted

Hey manumqln. Upgrading is easy if you follow the migration guide:

 

Posted

@mikel You're using GSAP's random functionality and a hand-written random function in that demo. Why not just use GSAP's random functionality? 

[prop]: gsap.utils.random(min, max)

 

  • Like 1
Posted

 

Hey ZACH,

 

Good point. I was too quick to migrate ...

 

Thanks ...

Mikel

Posted

@mikel this is very helpful. But I would like to bounce the items when they meet each other rather than overlapping. 

Posted
32 minutes ago, manumqln said:

I would like to bounce the items when they meet each other rather than overlapping. 

That's quite different than what you currently have :) You'll have to implement direction tracking (at the least the angle it's going at), hit detection for all of the boxes, and then each time they "hit" you will need to create a new animation that goes in a new direction based on which edge hit and the previous angle it was moving at. 

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