Skip to content

Commit fe32705

Browse files
Matt JaredMatt Jared
authored andcommitted
First video follow along
1 parent 5029405 commit fe32705

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

01 - JavaScript Drum Kit/index-START.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,21 @@
5858
<audio data-key="76" src="sounds/tink.wav"></audio>
5959

6060
<script>
61-
61+
function playSound(e) {
62+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
63+
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
64+
if(!audio) return;
65+
audio.currentTime = 0;
66+
audio.play();
67+
key.classList.toggle('playing');
68+
}
69+
function removeTransition(e){
70+
if (e.propertyName !== 'transform') return;
71+
this.classList.remove('playing');
72+
}
73+
const keys = document.querySelectorAll('.key');
74+
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
75+
window.addEventListener('keydown', playSound);
6276
</script>
6377

6478

0 commit comments

Comments
 (0)