File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 6060< script >
6161window . addEventListener ( "keydown" , function ( e ) {
6262 const audio = document . querySelector ( `audio[data-key="${ e . keyCode } "]` ) ;
63- if ( ! audio ) return ; // will stop the function from running.
64- console . log ( audio ) ;
63+ const key = document . querySelector ( `.key[data-key="${ e . keyCode } "]` )
64+ if ( ! audio ) return ; // will stop the function from running
65+ audio . currentTime = 0 ;
6566 audio . play ( ) ;
67+ key . classList . add ( "playing" ) ;
6668} ) ;
69+ function removeTransition ( e ) {
70+ if ( e . propertyName !== "transform" ) return ; // skip if not a transform
71+ console . log ( e . propertyName ) ;
72+ this . classList . remove ( "playing" ) ;
73+ }
74+ const keys = document . querySelectorAll ( ".key" ) ;
75+ keys . forEach ( key => key . addEventListener ( "transitionend" , removeTransition ) ) ;
6776</ script >
6877
6978
You can’t perform that action at this time.
0 commit comments