@@ -3,6 +3,7 @@ import { motion } from "framer-motion";
33type ExplosionProps = {
44 colour1 : string ;
55 colour2 : string ;
6+ // looks better with odd numbers
67 count : number ;
78 // can optionally take offsets to adjust exact position
89 yOffset ?: number ;
@@ -17,28 +18,38 @@ const Explosion = ({
1718 xOffset = 0 ,
1819} : ExplosionProps ) => {
1920 const particles = Array . from ( { length : count } ) ;
20- const randomDisplacement = Math . random ( ) * 10 ;
2121
2222 return (
23- < div className = "pointer-events-none absolute inset-0 flex items-center justify-center" >
24- { particles . map ( ( _ , i ) => (
25- < motion . div
26- key = { i }
27- initial = { { x : xOffset , y : yOffset , opacity : 1 , scale : 1 } }
28- animate = { {
29- x : Math . cos ( i + randomDisplacement ) * 150 + xOffset ,
30- y : Math . sin ( i + randomDisplacement ) * 150 + yOffset ,
31- opacity : 0 ,
32- scale : 0 ,
33- } }
34- transition = { { duration : 0.6 , ease : "easeOut" } }
35- className = "absolute h-10 w-10 rounded-none"
36- style = { {
37- backgroundColor : i % 2 === 0 ? colour1 : colour2 ,
38- boxShadow : `0 0 10px ${ colour1 } ` ,
39- } }
40- />
41- ) ) }
23+ < div className = "pointer-events-none absolute inset-0 z-0 flex items-center justify-center" >
24+ { particles . map ( ( _ , i ) => {
25+ const individualSize = Math . random ( ) * 0.1 + 4 ;
26+ const randomDisplacement = Math . random ( ) * 10 ;
27+
28+ // for every item in map, return a particle with a different size
29+ return (
30+ < motion . div
31+ key = { i }
32+ initial = { {
33+ x : xOffset ,
34+ y : yOffset ,
35+ opacity : 1 ,
36+ scale : individualSize ,
37+ } }
38+ animate = { {
39+ x : Math . cos ( i + randomDisplacement ) * 150 + xOffset ,
40+ y : Math . sin ( i + randomDisplacement ) * 150 + yOffset ,
41+ opacity : 0 ,
42+ scale : 0 ,
43+ } }
44+ transition = { { duration : 0.6 , ease : "easeOut" } }
45+ className = "absolute h-4 w-4 rounded-none"
46+ style = { {
47+ backgroundColor : i % 2 === 0 ? colour1 : colour2 ,
48+ boxShadow : `0 0 10px ${ colour1 } ` ,
49+ } }
50+ />
51+ ) ;
52+ } ) }
4253 </ div >
4354 ) ;
4455} ;
0 commit comments