Skip to content

Commit f649fc0

Browse files
committed
Completed Drum Kit
1 parent 17fff43 commit f649fc0

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

01 - JavaScript Drum Kit/index-START.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@
5959

6060
<script>
6161

62+
function removeTransition(e){
63+
if(e.propertyName != 'transform') return;
64+
e.target.classList.remove('playing');
65+
}
66+
67+
function playSound(event){
68+
const audio = document.querySelector(`audio[data-key="${event.keyCode}"]`);
69+
const key = document.querySelector(`div[data-key="${event.keyCode}"]`);
70+
if(!audio) return;
71+
72+
key.classList.add('playing');
73+
audio.currentTime = 0;
74+
audio.play();
75+
}
76+
77+
const keys = Array.from(document.querySelectorAll('.key'));
78+
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
79+
window.addEventListener('keydown', playSound);
6280
</script>
6381

6482

0 commit comments

Comments
 (0)