Jump to content
Search Community

How to show hide images randomly

ManishDev18 test
Moderator Tag

Recommended Posts

Hi @ManishDev18 welcome to the forum!

 

What have you tried your self already? What I would do is just display all the images how you would like them and stack them right on top of each other. Then with GSAP, just show and hide them. 

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo:

 

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen

 

Just try something and when you're stuck post back here with your demo. 

 

If you need help getting started, check out the Greensock Youtube Channel https://www.youtube.com/c/GreenSockLearning/videos

 

Hope it helps and happy tweening! 

Link to comment
Share on other sites

Hey, thanks for the reply. I tried solving this problem. 

There are some problems I'm facing.

1. As you said stack all the elements on to top of each other and show hide elements. What I did is to create a function named shuffleCircle. Created a timeline for showing or hiding the elements. I have to repeat the animation infinitely so I have called the same function once the animation is completed with onComplete property.
 

But, I need gap between individual function calls. How to create a gap between the animation once a timeline is succefully completed.

Codepen URL: 

See the Pen vYvzXxp?editors=0010 by manish1269 (@manish1269) on CodePen

Link to comment
Share on other sites

You are looking to delay the call of the onComplete for X amount of seconds? Check out gsap.delayedCall(); https://greensock.com/docs/v3/GSAP/gsap.delayedCall()

 

I would also look in to shuffling the array of elements and then using that array as the order, in your current setup the same element can be called right after each other I think? If you just get the array of every item and shuffle them [3, 6, 1, 4, 2] that will be not an issue. 

 

Hope it helps and happy tweening! 

 

See the Pen qBLJNXz?editors=0011 by mvaneijgen (@mvaneijgen) on CodePen

  • Like 2
Link to comment
Share on other sites

Welcome to the forum @ManishDev18,

 

In addition to @mvaneijgen's always great advice and guidance, I thought it might be good to include this post from an older thread. It’s directly related to your initial screenshot although older and would need to be migrated to GSAP 3 with all its newer available features & utility methods, etc.

 

Maybe it will also be useful to someone.

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