-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
44 lines (35 loc) · 1.12 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
let crashRide = document.querySelector("#crash-ride")
let hiHatTop = document .querySelector("#hihat-top")
const animateCrashOrRide = () =>{
crashRide.style.transform = "rotate(0deg) scale(1.5)"
}
const animateHiHatClosed = () => {
hiHatTop.style.top = "171px"
}
window.addEventListener("keydown", (event) =>{
let kod = event.keyCode
let key = document.querySelector(`div[data-key="${kod}"]`);
if (!key) return
let audio = document.querySelector(`audio[data-key="${kod}"]`)
audio.currentTime = 0
audio.play()
switch (kod) {
case 69:
case 82:
animateCrashOrRide();
break;
case 75:
animateHiHatClosed()
break
}
})
const removeCrashRideTransition = e => {
if (e.propertyName !== "transform") return
e.target.style.transform = "rotate(-7.2deg) scale(1.5)"
}
const removeHiHatTopTransition = e => {
if (e.propertyName !== "top") return
e.target.classList.remove("playing")
}
crashRide.addEventListener("transitionend", removeCrashRideTransition)
hiHatTop.addEventListener("transitionend", removeHiHatTopTransition)