@@ -30,6 +30,53 @@ function playFart(fart, randomPitch) {
30
30
shaking = true ;
31
31
}
32
32
33
+ function emitParticles ( pos ) {
34
+ let clickMeRect = clickMeText . getBoundingClientRect ( ) ;
35
+ console . log ( "rect" , clickMeRect ) ;
36
+ function rand ( multiplier ) {
37
+ return ( Math . random ( ) - 0.5 ) * multiplier ;
38
+ }
39
+ function createBlock ( pos , w , h , color ) {
40
+ var block = document . createElement ( "div" ) ;
41
+ block . style . position = "absolute" ;
42
+ block . style . left = pos . x + "px" ;
43
+ block . style . top = pos . y + "px" ;
44
+ block . style . width = w + "px" ;
45
+ block . style . height = h + "px" ;
46
+ block . style . backgroundColor = color ;
47
+ block . style . borderRadius = "50%" ;
48
+ block . style . pointerEvents = "none" ;
49
+ document . body . appendChild ( block ) ;
50
+ return block ;
51
+ }
52
+ let blocks = [
53
+ createBlock ( pos , 35 , 35 , "#572C25" ) ,
54
+ createBlock ( { x : pos . x + rand ( 30 ) , y : pos . y + rand ( 30 ) } , 30 , 30 , "#692A22" ) ,
55
+ createBlock ( { x : pos . x + rand ( 30 ) , y : pos . y + rand ( 30 ) } , 30 , 30 , "#662C24" ) ,
56
+ createBlock ( { x : pos . x + rand ( 30 ) , y : pos . y + rand ( 30 ) } , 20 , 20 , "#572A22" ) ,
57
+ createBlock ( { x : pos . x + rand ( 30 ) , y : pos . y + rand ( 30 ) } , 20 , 20 , "#672115" ) ,
58
+ createBlock ( { x : pos . x + rand ( 30 ) , y : pos . y + rand ( 30 ) } , 15 , 15 , "#572A22" ) ,
59
+ createBlock ( { x : pos . x + rand ( 30 ) , y : pos . y + rand ( 30 ) } , 10 , 10 , "#692A22" ) ,
60
+ createBlock ( { x : pos . x + rand ( 30 ) , y : pos . y + rand ( 30 ) } , 10 , 10 , "#662C24" ) ,
61
+ ] ;
62
+
63
+ blocks . forEach ( ( block ) => {
64
+ const blockSpinning = [
65
+ { opacity : 1 , transform : "translateX(0) translateY(0)" } ,
66
+ { opacity : 0 , transform : `translateX(${ rand ( 50 ) } px) translateY(${ rand ( 50 ) } px)` } ,
67
+ ] ;
68
+
69
+ const blockTiming = {
70
+ duration : 270 ,
71
+ iterations : 1 ,
72
+ } ;
73
+ let anim = block . animate ( blockSpinning , blockTiming ) ;
74
+ anim . addEventListener ( "finish" , ( ) => {
75
+ block . remove ( ) ;
76
+ } ) ;
77
+ } ) ;
78
+ }
79
+
33
80
const regularAction = ( ) => {
34
81
clickMeText . innerText = `Congrats! You clicked it ${ counter } times!` ;
35
82
playFart ( regularFart , true ) ;
@@ -180,10 +227,11 @@ let shaking = false;
180
227
let counter = 0 ; // TODO: DONT FORGET TO SET TO 0 ON RELEASE!!!
181
228
182
229
// TODO: change it to onmousedown (it stopped working after separating button and label)
183
- clickMe . onclick = ( ) => {
230
+ clickMe . onclick = ( e ) => {
184
231
counter += 1 ;
185
232
popupText . innerText = counter + "🍑💨" ;
186
233
fireEvents ( ) ;
234
+ emitParticles ( { x : e . clientX , y : e . clientY } ) ;
187
235
} ;
188
236
189
237
let prevTimestamp = 0 ;
0 commit comments