Re:A useful front-end confetti animation library
by amelius on Thursday April 25, 2024 @11:17AM
(#40158576)
What if you wanted to add the requirement that the user had to click on 1 specific piece of confetti?
[ Parent
| on HN ]
Re:A useful front-end confetti animation library
by nicky0 on Thursday April 25, 2024 @11:28AM
(#40158721)
Then you have a fun programming challenge.
Re:A useful front-end confetti animation library
by MartijnHols on Thursday April 25, 2024 @01:14PM
(#40160294)
Add a click event listener to the body and overlay the event-coordinates on the canvas.
Re:A useful front-end confetti animation library
by amelius on Thursday April 25, 2024 @02:11PM
(#40161067)
Will the canvas allow you to hit-test the confetti piece given the coordinate?
Re:A useful front-end confetti animation library
by eyelidlessness on Thursday April 25, 2024 @03:57PM
(#40162258)
Canvas draws raster images, anything resembling an object in your drawing logic is already tracked separately by necessity. So regardless, you’d presumably check against whatever data model you’re using to determine what to draw.
Re:A useful front-end confetti animation library
by lupire on Thursday April 25, 2024 @06:20PM
(#40163795)
By what time the user clicks, there's no reason for the program to need to remember what they drew where.
Re:A useful front-end confetti animation library
by eyelidlessness on Thursday April 25, 2024 @10:17PM
(#40165285)
If that’s the case, what other object with coordinates would you reference on a canvas to determine whether it was clicked?