-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
180 lines (171 loc) · 5.26 KB
/
index.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JS Drum Kit</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="keys">
<div data-key="65" class="key">
<kbd>A</kbd>
<span class="sound">clap</span>
</div>
<div data-key="83" class="key">
<kbd>S</kbd>
<span class="sound">hihat</span>
</div>
<div data-key="68" class="key">
<kbd>D</kbd>
<span class="sound">kick</span>
</div>
<div data-key="70" class="key">
<kbd>F</kbd>
<span class="sound">openhat</span>
</div>
<div data-key="71" class="key">
<kbd>G</kbd>
<span class="sound">boom</span>
</div>
<div data-key="72" class="key">
<kbd>H</kbd>
<span class="sound">ride</span>
</div>
<div data-key="74" class="key">
<kbd>J</kbd>
<span class="sound">snare</span>
</div>
<div data-key="75" class="key">
<kbd>K</kbd>
<span class="sound">tom</span>
</div>
<div data-key="76" class="key">
<kbd>L</kbd>
<span class="sound">tink</span>
</div>
<div data-key="90" class="key">
<kbd>Z</kbd>
<span class="sound">twinkle synth</span>
</div>
<div data-key="88" class="key">
<kbd>X</kbd>
<span class="sound">drum beat</span>
</div>
<div data-key="67" class="key">
<kbd>C</kbd>
<span class="sound">bass</span>
</div>
<div data-key="86" class="key">
<kbd>V</kbd>
<span class="sound">drum synth</span>
</div>
<div data-key="66" class="key">
<kbd>B</kbd>
<span class="sound">guitar melody</span>
</div>
<div data-key="78" class="key">
<kbd>N</kbd>
<span class="sound">more guitar</span>
</div>
<div data-key="77" class="key">
<kbd>M</kbd>
<span class="sound">chew</span>
</div>
<div data-key="81" class="key">
<kbd>Q</kbd>
<span class="sound">sparkle</span>
</div>
<div data-key="87" class="key">
<kbd>W</kbd>
<span class="sound">bass guitar</span>
</div>
<div data-key="69" class="key">
<kbd>E</kbd>
<span class="sound">juno</span>
</div>
<div data-key="82" class="key">
<kbd>R</kbd>
<span class="sound">oldie beat</span>
</div>
<div data-key="84" class="key">
<kbd>T</kbd>
<span class="sound">metal guitar</span>
</div>
<div data-key="89" class="key">
<kbd>Y</kbd>
<span class="sound">cog beat</span>
</div>
<div data-key="85" class="key">
<kbd>U</kbd>
<span class="sound">chill guitar</span>
</div>
<div data-key="73" class="key">
<kbd>I</kbd>
<span class="sound">chill waves</span>
</div>
<div data-key="79" class="key">
<kbd>O</kbd>
<span class="sound">speed beat</span>
</div>
<div data-key="80" class="key">
<kbd>P</kbd>
<span class="sound">dubby</span>
</div>
</div>
<!-- drum sounds -->
<audio data-key="65" src="sounds/clap.wav"></audio>
<audio data-key="83" src="sounds/hihat.wav"></audio>
<audio data-key="68" src="sounds/kick.wav"></audio>
<audio data-key="70" src="sounds/openhat.wav"></audio>
<audio data-key="71" src="sounds/boom.wav"></audio>
<audio data-key="72" src="sounds/ride.wav"></audio>
<audio data-key="74" src="sounds/snare.wav"></audio>
<audio data-key="75" src="sounds/tom.wav"></audio>
<audio data-key="76" src="sounds/tink.wav"></audio>
<!-- instrumentals -->
<audio data-key="90" src="sounds/twinkleSynth.wav"></audio>
<audio data-key="88" src="sounds/drum.wav"></audio>
<audio data-key="67" src="sounds/lilBass.wav"></audio>
<audio data-key="86" src="sounds/drumSynth.wav"></audio>
<audio data-key="66" src="sounds/guitarMelody.wav"></audio>
<audio data-key="78" src="sounds/guitar.wav"></audio>
<audio data-key="77" src="sounds/chew.wav"></audio>
<audio data-key="81" src="sounds/sparkleSynth.wav"></audio>
<audio data-key="87" src="sounds/bassGuitar.wav"></audio>
<audio data-key="69" src="sounds/junoSynth.wav"></audio>
<audio data-key="82" src="sounds/oldBeat.wav"></audio>
<audio data-key="84" src="sounds/metalGuitar.wav"></audio>
<audio data-key="89" src="sounds/cogBeat.wav"></audio>
<audio data-key="85" src="sounds/chillGuitar.wav"></audio>
<audio data-key="73" src="sounds/chillWaves.wav"></audio>
<audio data-key="79" src="sounds/speedBeat.wav"></audio>
<audio data-key="80" src="sounds/dubbyBeat.wav"></audio>
<script>
function playSound(keyCode) {
const audio = document.querySelector(`audio[data-key="${keyCode}"]`);
const key = document.querySelector(`.key[data-key="${keyCode}"]`);
if (!audio) return;
audio.currentTime = 0;
audio.play();
key.classList.add('playing');
}
function handleClick(e) {
const keyCode = e.currentTarget.getAttribute('data-key');
playSound(keyCode);
}
function handleKeydown(e) {
playSound(e.keyCode);
}
function removeTransition(e) {
if (e.propertyName !== 'transform') return;
this.classList.remove('playing');
}
const keys = document.querySelectorAll('.key');
keys.forEach(key => {
key.addEventListener('transitionend', removeTransition);
key.addEventListener('click', handleClick);
});
window.addEventListener('keydown', handleKeydown);
</script>
</body>
</html>