File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 5959
6060< script >
6161
62+ //HJW
63+ function playSound ( e ) {
64+ console . log ( e . keyCode ) ;
65+ const audio = document . querySelector ( `audio[data-key="${ e . keyCode } "` ) ;
66+ const key = document . querySelector ( `.key[data-key="${ e . keyCode } "` ) ;
67+ console . log ( audio ) ;
68+ if ( ! audio ) return ;
69+ console . log ( key ) ;
70+ audio . currentTime = 0 ;
71+ audio . play ( ) ;
72+ key . classList . add ( 'playing' ) ;
73+ }
74+
75+ function removeTransition ( e ) {
76+ if ( e . propertyName !== 'transform' ) return ;
77+ console . log ( e . propertyName ) ;
78+ console . log ( this ) ;
79+ this . classList . remove ( 'playing' ) ;
80+ }
81+
82+ const keys = document . querySelectorAll ( '.key' )
83+ keys . forEach ( key => key . addEventListener ( 'transitionend' , removeTransition ) ) ;
84+ window . addEventListener ( 'keydown' , playSound ) ;
85+
6286</ script >
6387
6488
You can’t perform that action at this time.
0 commit comments