File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed
Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change 11const buttons = document . querySelectorAll ( ".ripple" ) ;
22
3+ function getClickPosition ( e , element ) {
4+ const x = e . clientX ;
5+ const y = e . clientY ;
6+ const buttonTop = element . offsetTop ;
7+ const buttonLeft = element . offsetLeft ;
8+ return {
9+ xInside : x - buttonLeft ,
10+ yInside : y - buttonTop ,
11+ } ;
12+ }
13+
314buttons . forEach ( ( button ) => {
415 button . addEventListener ( "click" , function ( e ) {
5- const x = e . clientX ;
6- const y = e . clientY ;
7- const buttonTop = e . target . offsetTop ;
8- const buttonLeft = e . target . offsetLeft ;
9- const xInside = x - buttonLeft ;
10- const yInside = y - buttonTop ;
16+ const { xInside, yInside } = getClickPosition ( e , this ) ;
1117 const circle = document . createElement ( "span" ) ;
1218 circle . classList . add ( "circle" ) ;
1319 circle . style . top = yInside + "px" ;
You can’t perform that action at this time.
0 commit comments