We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 61b13da commit a8fa888Copy full SHA for a8fa888
01 - JavaScript Drum Kit/index-START.html
@@ -59,6 +59,28 @@
59
60
<script>
61
62
+ function playSound(e){
63
+ const audio = document.querySelector(`audio[data-key="${e.keyCode}"`)
64
+ const currKey = document.querySelector(`.key[data-key="${e.keyCode}"`)
65
+
66
+ if (!audio) return;
67
68
+ audio.currentTime = 0; //rewind to start allowing repeated clicks
69
+ audio.play();
70
+ currKey.classList.add('playing');
71
+ }
72
73
+ function removeTransition(e){
74
+ if(e.propertyName !== "transform") return;
75
+ this.classList.remove('playing');
76
77
78
79
+ (() => {
80
+ document.addEventListener('keydown', playSound);
81
+ const keys = document.querySelectorAll('.key');
82
+ keys.forEach(key => key.addEventListener('transitionend', removeTransition));
83
+ })();
84
</script>
85
86
0 commit comments