File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 5959
6060< script >
6161
62+
63+
64+ function playSound ( e ) {
65+ const audio = document . querySelector ( `audio[data-key="${ e . keyCode } "]` ) ;
66+ const key = document . querySelector ( `.key[data-key="${ e . keyCode } "]` ) ;
67+ if ( ! audio ) return ; //stop the function from running all together
68+ audio . currentTime = 0 //rewind to the start
69+ audio . play ( ) ;
70+ key . classList . add ( 'playing' )
71+ }
72+
73+ function removeTransition ( e ) {
74+ if ( e . propertyName !== 'transform' ) return
75+ this . classList . remove ( 'playing' )
76+ }
77+
78+ const keys = document . querySelectorAll ( '.key' ) ;
79+ keys . forEach ( key => key . addEventListener ( 'transitionend' , removeTransition ) )
80+
81+ window . addEventListener ( 'keydown' , playSound ) ;
6282</ script >
6383
6484
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ body,html {
3232}
3333
3434.playing {
35- transform : scale (1.1 );
35+ transform : scale (4 );
3636 border-color : # ffc600 ;
3737 box-shadow : 0 0 10px # ffc600 ;
3838}
You can’t perform that action at this time.
0 commit comments