File tree Expand file tree Collapse file tree 2 files changed +9
-76
lines changed Expand file tree Collapse file tree 2 files changed +9
-76
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 58
58
< audio data-key ="76 " src ="sounds/tink.wav "> </ audio >
59
59
60
60
< script >
61
- function removeTransition ( e ) {
62
- if ( e . propertyName !== 'transform' ) return ;
63
- e . target . classList . remove ( 'playing' ) ;
64
- }
65
-
66
61
function playSound ( e ) {
62
+ // console.log(e.keyCode);
67
63
const audio = document . querySelector ( `audio[data-key="${ e . keyCode } "]` ) ;
68
- const key = document . querySelector ( `div [data-key="${ e . keyCode } "]` ) ;
64
+ const key = document . querySelector ( `.key [data-key="${ e . keyCode } "]` ) ;
69
65
if ( ! audio ) return ;
70
-
71
- key . classList . add ( 'playing' ) ;
72
66
audio . currentTime = 0 ;
73
67
audio . play ( ) ;
68
+ key . classList . add ( 'playing' ) ;
69
+ }
70
+
71
+ function removeTransition ( e ) {
72
+ if ( e . propertyName !== 'transform' ) return ;
73
+ this . classList . remove ( 'playing' ) ;
74
74
}
75
75
76
- const keys = Array . from ( document . querySelectorAll ( '.key' ) ) ;
76
+ const keys = document . querySelectorAll ( '.key' ) ;
77
77
keys . forEach ( key => key . addEventListener ( 'transitionend' , removeTransition ) ) ;
78
78
window . addEventListener ( 'keydown' , playSound ) ;
79
79
</ script >
80
80
81
-
82
81
</ body >
83
82
</ html >
You can’t perform that action at this time.
0 commit comments