File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
01 - JavaScript Drum Kit/js Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 1+ function playSound ( e ) {
2+ const audio = document . querySelector ( `audio[data-key= "${ e . keyCode } "]` ) ;
3+ const key = document . querySelector ( `.key[data-key= "${ e . keyCode } "]` ) ;
4+ console . log ( audio ) ;
5+ if ( ! audio ) return ; // stop the function from running
6+ audio . currentTime = 0 ; // rewind to the start
7+ audio . play ( ) ;
8+ key . classList . add ( 'playing' ) ;
9+ }
10+
11+ function removeTransition ( e ) {
12+ if ( e . propertyName !== 'transform' ) return ; // skip if it's not a transform
13+
14+ this . classList . remove ( 'playing' ) ;
15+ }
16+
17+ const keys = document . querySelectorAll ( '.key' ) ;
18+ keys . forEach ( key => key . addEventListener ( 'transitionend' , removeTransition ) ) ;
19+
20+ window . addEventListener ( 'keydown' , playSound ) ;
You can’t perform that action at this time.
0 commit comments