Home > front end >  How to make GSAP marquee item change line immediately, not waiting all items finished animation?
How to make GSAP marquee item change line immediately, not waiting all items finished animation?

Time:12-06

I'm Oliver, a noob of web animation,these two days I'm trying to do gsap marquee side project, I build 500 dom boxes as the sandbox url:

https://codesandbox.io/s/gsap-marquee-test-6zx2d?file=/src/App.js&fbclid=IwAR1tbmloHRXHUBHKG5FjBGDAx0TFd9sTkBJfSwpye8CQteO-TO8FNi1w4mw

and I have few question:

1.I used setTimeout to seperate each box as a unique timeline animation,so that the single box animation could go to another line immediately after finished last line, instead of waiting the other 499 boxs finished in the same line if I use property stagger.

This method would produce 500 timeline instances,it seems not a good idea, are there any methods could produce the same animation in one or few timeline?

2.If I do such animation in canvas,the browser render effciency would be better?

CodePudding user response:

You should avoid using setTimeout with GSAP as it's best to use GSAP to control the timing of things.

In this situation, you can probably make use of GSAP's staggers. You should also learn about the position parameter of GSAP's timelines. If you use one (or both, depending on the exact effect that you need) of these you should be able to avoid creating so many timelines.

Additionally, your animation is not responsive. You probably want to make use of functional properties (where your properties of a tween are functions, not just hard numbers) with timeline invalidation to make it responsive.

I also highly recommend going through the most common GSAP mistakes article as you're making some of them.

As for using canvas for rendering your boxes, it probably depends on what your boxes are like. In most cases it'd probably be faster to use canvas, yes. But the slow part of animating these boxes is not anything related to the animation functionality itself, per se. It's related to render speed. In general it's faster to render a bunch of objects to canvas than it is to render a bunch of DOM elements.

  • Related