-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrum-kit.html
120 lines (109 loc) · 2.83 KB
/
drum-kit.html
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Drum Kit</title>
<link rel="stylesheet" href="style.css">
<style>@import url('https://fonts.googleapis.com/css?family=Comfortaa:300|Open+Sans&display=swap');</style>
</head>
<body>
<style>
html {
font-size: 10px;
background: url(https://i.imgur.com/3SqnKum.jpg) bottom center;
background-size: cover;
}
body,html {
margin: 0;
padding: 0;
font-family: Comfortaa;
}
.keys {
display: flex;
flex: 1;
min-height: 100vh;
align-items: center;
justify-content: center;
}
.key {
border: .4rem solid black;
border-radius: .5rem;
margin: 1rem;
font-size: 1.5rem;
padding: 1rem .5rem;
transition: all .07s ease;
width: 10rem;
text-align: center;
color: white;
background: rgba(0,0,0,0.4);
text-shadow: 0 0 .5rem black;
}
.playing {
transform: scale(1.1);
border-color: #ffc600;
box-shadow: 0 0 1rem #ffc600;
}
kbd {
display: block;
font-size: 4rem;
font-family: Comfortaa;
}
.sound {
font-size: 1.2rem;
text-transform: uppercase;
letter-spacing: .1rem;
color: #ffc600;
}
</style>
<div class="keys">
<div data-key="77" class="key">
<kbd>M</kbd>
<span class="sound">clap</span>
</div>
<div data-key="69" class="key">
<kbd>E</kbd>
<span class="sound">hihat</span>
</div>
<div data-key="65" class="key">
<kbd>A</kbd>
<span class="sound">kick</span>
</div>
<div data-key="71" class="key">
<kbd>G</kbd>
<span class="sound">openhat</span>
</div>
<div data-key="65" class="key">
<kbd>A</kbd>
<span class="sound">boom</span>
</div>
<div data-key="78" class="key">
<kbd>N</kbd>
<span class="sound">ride</span>
</div>
</div>
<audio data-key="77" src="sounds/clap.wav"></audio>
<audio data-key="69" src="sounds/hihat.wav"></audio>
<audio data-key="65" src="sounds/kick.wav"></audio>
<audio data-key="71" src="sounds/openhat.wav"></audio>
<audio data-key="65" src="sounds/boom.wav"></audio>
<audio data-key="78" src="sounds/ride.wav"></audio>
<script>
function removeTransition(e) {
if (e.propertyName !== 'transform') return;
console.log(e.target.classList);
e.target.classList.remove('playing');
}
function playSound(e) {
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
const key = document.querySelectorAll(`div[data-key="${e.keyCode}"]`);
if (!audio) return;
key.forEach(key => key.classList.add('playing'));
audio.currentTime = 0;
audio.play();
}
const keys = Array.from(document.querySelectorAll('.key'));
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
window.addEventListener('keydown', playSound);
</script>
</body>
</html>