athuillier
Content Type
Profiles
Forums
Store
Blog
Product
Showcase
FAQ
Downloads
Posts posted by athuillier
-
-
Hello,
I've created a set of 9 animations triggered by pressing keyboard keys [QWE][ASD][ZXC].
My question is about the animation triggered when pressing "C" key (i.e. the 14 small colorful rectangles arriving on the canvas).
These elements are SVG <rect> grouped under a <g id="confettis">.
I defined a function playConfettis() where I randomly move each <rect>. Here is a simplified version of this function :
function playConfettis() {
tl.set(theConfettis, { rotation:0, x:0, y:0 })
.to(theConfetti1, .3, { rotation:rand(-360,360), x:rand(-500,500), y:rand(0,-500) }).to(theConfetti2, .3, { rotation:rand(-360,360), x:rand(-500,500), y:rand(0,-500) })
...AND SO ON FOR EACH
}
I guess my code is not optimized, but I couldn't figure out how to loop through all those <rect>.
Thank in advance for your suggestions
See the Pen JpLvbM by athuillier (@athuillier) on CodePen
- 1
Looping through children of a SVG <g>
in GSAP
Posted
Thank you @Sahil for pointing that out. I did try staggerTo but it couldn't work.
@PointC your second approach is super clear, thanks for that!