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 6faed6d commit ac5b3c4Copy full SHA for ac5b3c4
01 - JavaScript Drum Kit/index-START.html
@@ -58,7 +58,25 @@
58
<audio data-key="76" src="sounds/tink.wav"></audio>
59
60
<script>
61
+function playSound(e){
62
+ const keyPressed = e.keyCode;
63
+ const audio = document.querySelector(`audio[data-key="${keyPressed}"]`)
64
+ const key = document.querySelector(`.key[data-key="${keyPressed}"]`)
65
+ if(!audio) return
66
+ key.classList.add('playing')
67
+ audio.currentTime = 0;
68
+ audio.play();
69
+}
70
+function removeTransition(e){
71
+ if(e.propertyName !== "transform") return
72
+ this.classList.remove('playing')
73
74
+const keys = document.querySelectorAll('.key')
75
+keys.forEach(key => {
76
+ key.addEventListener('transitionend', removeTransition)
77
+})
78
79
+window.addEventListener('keydown', playSound)
80
</script>
81
82
0 commit comments