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 1
1
const buttons = document . querySelectorAll ( ".ripple" ) ;
2
2
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
+
3
14
buttons . forEach ( ( button ) => {
4
15
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 ) ;
11
17
const circle = document . createElement ( "span" ) ;
12
18
circle . classList . add ( "circle" ) ;
13
19
circle . style . top = yInside + "px" ;
You can’t perform that action at this time.
0 commit comments