Skip to content

Commit 4d32bf7

Browse files
finished drum machine
1 parent 38a754c commit 4d32bf7

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

01 - JavaScript Drum Kit/index-START.html

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

6060
<script>
6161

62+
63+
64+
function playSound(e){
65+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
66+
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
67+
if(!audio) return; //stop the function from running all together
68+
audio.currentTime = 0 //rewind to the start
69+
audio.play();
70+
key.classList.add('playing')
71+
}
72+
73+
function removeTransition(e){
74+
if (e.propertyName !== 'transform') return
75+
this.classList.remove('playing')
76+
}
77+
78+
const keys = document.querySelectorAll('.key');
79+
keys.forEach(key=> key.addEventListener('transitionend', removeTransition))
80+
81+
window.addEventListener('keydown', playSound);
6282
</script>
6383

6484

01 - JavaScript Drum Kit/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ body,html {
3232
}
3333

3434
.playing {
35-
transform:scale(1.1);
35+
transform:scale(4);
3636
border-color:#ffc600;
3737
box-shadow: 0 0 10px #ffc600;
3838
}

0 commit comments

Comments
 (0)