File tree Expand file tree Collapse file tree 4 files changed +26
-3
lines changed Expand file tree Collapse file tree 4 files changed +26
-3
lines changed Original file line number Diff line number Diff line change 1+
2+
3+
4+
5+ function playSound ( e ) {
6+ const audio = document . querySelector ( `audio[data-key="${ e . keyCode } "]` ) ;
7+ const key = document . querySelector ( `.key[data-key="${ e . keyCode } "]` ) ;
8+ if ( ! audio ) return ; //stop function from running all together
9+ audio . currentTime = 0 ; // rewind to start
10+ audio . play ( ) ;
11+ key . classList . add ( 'playing' ) ;
12+ }
13+ function removeTransition ( e ) {
14+ if ( e . propertyName !== 'transform' )
15+ return ; //skip if its not a transform
16+ this . classList . remove ( 'playing' )
17+ }
18+
19+ const keys = document . querySelectorAll ( '.key' ) ;
20+ keys . forEach ( key => key . addEventListener ( 'transitionend' , removeTransition ) ) ;
21+ window . addEventListener ( 'keydown' , playSound ) ;
Original file line number Diff line number Diff line change 5757 < audio data-key ="75 " src ="sounds/tom.wav "> </ audio >
5858 < audio data-key ="76 " src ="sounds/tink.wav "> </ audio >
5959
60- < script >
60+
61+ < script type ="text/javascript " src ="app.js ">
6162
6263</ script >
6364
Original file line number Diff line number Diff line change 7777 keys . forEach ( key => key . addEventListener ( 'transitionend' , removeTransition ) ) ;
7878 window . addEventListener ( 'keydown' , playSound ) ;
7979
80+
8081</ script >
8182
8283</ body >
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ body,html {
2323 margin : 1rem ;
2424 font-size : 1.5rem ;
2525 padding : 1rem .5rem ;
26- transition : all .07s ;
26+ transition : all 0 .07s ;
2727 width : 100px ;
2828 text-align : center;
2929 color : white;
@@ -32,7 +32,7 @@ body,html {
3232}
3333
3434.playing {
35- transform : scale (1 .1 );
35+ transform : scale (2 .1 );
3636 border-color : # ffc600 ;
3737 box-shadow : 0 0 10px # ffc600 ;
3838}
You can’t perform that action at this time.
0 commit comments