-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
61 lines (45 loc) · 1.45 KB
/
script.js
File metadata and controls
61 lines (45 loc) · 1.45 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
let crashRide = document.querySelector('#crash-ride');
let hiHatTop = document.querySelector('#hihat-top');
const animationCrashOrRide = () => {
crashRide.style.transform = 'rotate(0deg) scale(1.5)'
};
const animateHiHatClosed = () => {
hiHatTop.style.top = '171px'
}
window.addEventListener('keydown', (event) => {
let code = event.keyCode;
let keyELement = document.querySelector(`div[data-key="${code}"]`);
if(!keyELement) return;
let audio = document.querySelector(`audio[data-key="${code}"]`);
audio.currentTime = 0;
audio.play();
switch(code){
case 69:
case 82:
animationCrashOrRide();
break;
case 75:
case 73:
animateHiHatClosed();
break;
}
keyELement.classList.add('playing');
});
const removeCrashOrRide = e => {
if(e.propertyName !== 'transform') return;
e.target.style.transform = 'rotate(-7.2deg) scale(1.5)';
}
const removeHiHatClosed = e => {
if(e.propertyName !== 'top') return;
e.target.style.top = '166px';
}
const removeKeyTransition = e => {
if(e.propertyName !== 'transform') return;
e.target.classList.remove('playing')
}
let drumKeys = document.querySelectorAll('.key');
drumKeys.forEach((key) => {
key.addEventListener('transitioned', removeKeyTransition)
});
crashRide.addEventListener('transitionend', removeCrashOrRide);
hiHatTop.addEventListener('transitionend', removeHiHatClosed);