()
| 18 | |
| 19 | useEffect(() => { |
| 20 | const generateStars = () => { |
| 21 | if (buttonRef.current) { |
| 22 | const { width, height } = buttonRef.current.getBoundingClientRect() |
| 23 | setStars( |
| 24 | Array.from({ length: 50 }, (_, i) => ({ |
| 25 | id: i, |
| 26 | x: Math.random() * width, |
| 27 | y: Math.random() * height, |
| 28 | size: Math.random() * 2 + 1, |
| 29 | speed: Math.random() * 50 + 20, |
| 30 | })), |
| 31 | ) |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | generateStars() |
| 36 | window.addEventListener('resize', generateStars) |