File tree 1 file changed +12
-4
lines changed
1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change 1
1
document . addEventListener ( "DOMContentLoaded" , ( ) => {
2
2
3
+ const keys = document . querySelectorAll ( '.key' ) ; // save all keys in tab
4
+
3
5
window . addEventListener ( 'keydown' , function ( e ) {
4
- // e.keyCode
6
+ // e.keyCode --> get a code of the key
5
7
const audio = document . querySelector ( `audio[data-key="${ e . keyCode } "]` ) ;
6
8
const key = document . querySelector ( `.key[data-key="${ e . keyCode } "]` ) ;
7
9
if ( ! audio ) {
8
10
return
9
11
}
10
- audio . currentTime = 0 ;
11
- audio . play ( ) ;
12
+ audio . currentTime = 0 ; // this is for me to play immediately same button
13
+ audio . play ( ) ; //play sound
12
14
13
15
key . classList . add ( 'playing' ) ;
14
16
} )
15
17
16
-
18
+ keys . forEach ( elem => { // run through the keys
19
+ elem . addEventListener ( 'transitionend' , event => {
20
+ // lots of events - gimme only "transform" one
21
+ if ( event . propertyName !== 'transform' ) return ;
22
+ event . target . classList . remove ( 'playing' ) ;
23
+ } )
24
+ } )
17
25
18
26
} ) ;
You can’t perform that action at this time.
0 commit comments