File tree Expand file tree Collapse file tree 2 files changed +17
-83
lines changed Expand file tree Collapse file tree 2 files changed +17
-83
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 58
58
< audio data-key ="76 " src ="sounds/tink.wav "> </ audio >
59
59
60
60
< script >
61
+ function playsound ( e ) {
62
+ const audio = document . querySelector ( `audio[data-key="${ e . keyCode } "]` ) ;
63
+ const key = document . querySelector ( `.key[data-key="${ e . keyCode } "]` ) ;
64
+ if ( ! audio ) return ;
65
+ audio . currentTime = 0 ;
66
+ audio . play ( ) ;
67
+ key . classList . add ( 'playing' ) ;
68
+ } ;
61
69
70
+ function removeTransition ( e ) {
71
+ if ( e . propertyName !== 'transform' ) return ;
72
+ this . classList . remove ( 'playing' )
73
+ }
74
+
75
+ const keys = document . querySelectorAll ( '.key' ) ;
76
+ keys . forEach ( key => key . addEventListener ( 'transitionend' , removeTransition ) ) ;
77
+
78
+ window . addEventListener ( 'keydown' , playsound ) ;
62
79
</ script >
63
80
64
81
You can’t perform that action at this time.
0 commit comments