Jump to content
Search Community

dynamic add animation when previous animation is still running?

sejabs test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I am a newbie with html5 animation area and I found GSAP. It's a powerful tool! However, in my project, I faced a knotty problem:  there is a image producer which randomly output various images into a folder. I choose Chokidar to watch the folder and push the added image path to an array when 'add' event occur. Then I need periodically (e.g. 1s) choose the first element of the array to show it in the window frame and fade it within e.g. 3s.  When the animation is finished,  the array pop the element animated previously.

After using GSAP timeline, I realized the tool normally need all elements participating in the animation to be statically completely designed at start point. Maybe I am wrong? or any feasible ideas? Thanks!

Link to comment
Share on other sites

Hi Sejabs,

 

Welcome to the forums!

 

We always ask people to provide a reduced case example to make it easier to help. In your example what I think you are trying to achieve is quite straight foward but I am not sure I understood your situation correctly. So, if you could show us what is it that you are trying to achieve, would be of immense help. For example, I have no idea what Chokidar is. Nor I understand why you need to watch a folder and add an image path to an array if you are already watching said folder.

 

In regards to the GSAP specific bits, you are correct when you say the timeline expects all of its components to be present in order to do its job correctly. One of the reasons being it has to calculate the element's attributes before to tweening them. However, there are ways around it.

 

One such way would be to have a timeline do whatever animation it is that you want, pause at your desired point, call a function that would animate the new image from the array, including removing the element from said array at the end of it and then, at the end of this other animation, the timeline would be told to continue playing.

 

To me, it would be totally feasible. If I understand what you want correctly.

  • Like 4
Link to comment
Share on other sites

After self-learning for a while, I can solve mine problem. If I want to dynamically add a animation when previous animation is running, I can use the code above and change the added animation position from

i*0.25

to

t.time()

Cheer GSAP for its powerful!

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