File tree Expand file tree Collapse file tree 3 files changed +9
-100
lines changed Expand file tree Collapse file tree 3 files changed +9
-100
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 59
59
60
60
< script >
61
61
62
+
62
63
</ script >
63
64
64
65
Original file line number Diff line number Diff line change 59
59
60
60
< script >
61
61
62
-
63
- function playSound ( e ) {
64
- const audio = document . querySelector ( `audio[data-key="${ e . keyCode } "]` ) ;
65
- const key = document . querySelector ( `.key[data-key="${ e . keyCode } "]` ) ;
66
- if ( ! audio ) return ; // stop the function from running all together
67
- audio . currentTime = 0 ; // rewind to the start
68
- audio . play ( ) ;
69
- key . classList . add ( 'playing' ) ;
70
- }
71
- function removeTransition ( e ) {
72
- if ( e . propertyName !== 'transform' ) return ; // skip it if it's not a transform
73
- this . classList . remove ( 'playing' ) ;
74
- }
75
-
76
- const keys = document . querySelectorAll ( '.key' ) ;
77
- keys . forEach ( key => key . addEventListener ( 'transitionend' , removeTransition ) ) ;
78
- window . addEventListener ( 'keydown' , playSound ) ;
62
+ window . addEventListener ( "keydown" , function ( e ) {
63
+ const audio = document . querySelector ( `audio[data-key='${ e . keyCode } ']` ) ;
64
+ const key = document . querySelector ( `.key[data-key='${ e . keyCode } ']` ) ;
65
+ if ( ! audio ) return ;
66
+ audio . currentTime = 0 ; //rewind to start
67
+ audio . play ( )
68
+ key . classList . add ( 'playing' )
69
+ } ) ;
79
70
80
71
</ script >
81
72
You can’t perform that action at this time.
0 commit comments