File tree Expand file tree Collapse file tree 1 file changed +7
-19
lines changed Expand file tree Collapse file tree 1 file changed +7
-19
lines changed Original file line number Diff line number Diff line change 77</ head >
88< body >
99
10-
10+ <!-- Buttons -->
11+ <!-- Data attributes (data-key) wire up buttons with sounds -->
1112 < div class ="keys ">
1213 < div data-key ="65 " class ="key ">
1314 < kbd > A</ kbd >
4748 </ div >
4849 </ div >
4950
51+ <!-- Links to sound files that play on button press -->
5052 < audio data-key ="65 " src ="sounds/clap.wav "> </ audio >
5153 < audio data-key ="83 " src ="sounds/hihat.wav "> </ audio >
5254 < audio data-key ="68 " src ="sounds/kick.wav "> </ audio >
5860 < audio data-key ="76 " src ="sounds/tink.wav "> </ audio >
5961
6062< script >
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 altogether
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 ) ;
63+ window . addEventListener ( 'keydown' , function ( e ) {
64+ console . log ( e ) ;
65+ } ) ;
7966
8067</ script >
8168
69+
8270</ body >
8371</ html >
You can’t perform that action at this time.
0 commit comments