Skip to content

Commit e40b0c3

Browse files
committed
fix keydown to reset and add transition.
1 parent fc9030b commit e40b0c3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

01 - JavaScript Drum Kit/index-PROGRESS.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,19 @@
6060
<script>
6161
window.addEventListener("keydown", function(e) {
6262
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
63-
if (!audio) return; // will stop the function from running.
64-
console.log(audio);
63+
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`)
64+
if (!audio) return; // will stop the function from running
65+
audio.currentTime = 0;
6566
audio.play();
67+
key.classList.add("playing");
6668
});
69+
function removeTransition(e) {
70+
if (e.propertyName !== "transform") return; // skip if not a transform
71+
console.log(e.propertyName);
72+
this.classList.remove("playing");
73+
}
74+
const keys = document.querySelectorAll(".key");
75+
keys.forEach(key => key.addEventListener("transitionend", removeTransition));
6776
</script>
6877

6978

0 commit comments

Comments
 (0)