File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change 5858 < audio data-key ="76 " src ="sounds/tink.wav "> </ audio >
5959
6060< script >
61+
6162 window . addEventListener ( 'keydown' , function ( e ) {
6263
6364 const audio = document . querySelector ( `audio[data-key="${ e . keyCode } "]` ) ;
64- if ( ! audio ) return ;
65+ const key = document . querySelector ( `.key[data-key="${ e . keyCode } "]` )
66+ if ( ! audio ) return ; //stops function from running all together & prevents console error
67+
68+ audio . currentTime = 0 ; //rewinds audio to start, enable rapid keypress
6569 audio . play ( ) ;
66- console . log ( audio )
70+
71+ key . classList . add ( 'playing' ) ;
72+
6773 } ) ;
74+
75+ function removeTransition ( e ) {
76+ if ( e . propertyName !== 'transform' ) return ; //skip if not transform
77+ console . log ( e . propertyName ) ;
78+ }
79+
80+ const keys = document . querySelectorAll ( '.key' ) ;
81+ keys . forEach ( key => key . addEventListener ( 'transitionend' , removeTransition ) ) ;
82+
6883</ script >
6984
7085
You can’t perform that action at this time.
0 commit comments