Skip to content

Commit 1701c0c

Browse files
authored
Update drum.html
1 parent 3ea21ba commit 1701c0c

File tree

1 file changed

+74
-22
lines changed

1 file changed

+74
-22
lines changed

DrumKit/drum.html

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,83 @@
1-
<!DOCTYPE html>
2-
<html lang="en" dir="ltr">
3-
1+
<!DOCTYPE HTML>
2+
<html lang="en">
43
<head>
5-
<meta charset="utf-8">
6-
<title>Drum Kit</title>
4+
<meta charset="UTF-8">
5+
<title>JS Drum Kit</title>
76
<link rel="stylesheet" href="style.css">
8-
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@1,900&family=Recursive&display=swap" rel="stylesheet">
97
</head>
10-
118
<body>
129

13-
<h3 id="title" style="margin:10px 10px">DRUM 🥁 KIT</h3>
14-
<div class="set" style="margin:30px 10px">
15-
<button class="f drum">f</button>
16-
<button class="h drum">h</button>
17-
<button class="j drum">j</button>
18-
<BR>
19-
<button class="a drum">a</button>
20-
<button class="s drum">s</button>
21-
<button class="d drum">d</button>
22-
<button class="g drum">g</button>
2310

11+
<div class="keys">
12+
<div data-key="65" class="key">
13+
<kbd>A</kbd>
14+
<span class="sound">clap</span>
15+
</div>
16+
<div data-key="83" class="key">
17+
<kbd>S</kbd>
18+
<span class="sound">hihat</span>
19+
</div>
20+
<div data-key="68" class="key">
21+
<kbd>D</kbd>
22+
<span class="sound">kick</span>
23+
</div>
24+
<div data-key="70" class="key">
25+
<kbd>F</kbd>
26+
<span class="sound">openhat</span>
27+
</div>
28+
<div data-key="71" class="key">
29+
<kbd>G</kbd>
30+
<span class="sound">boom</span>
31+
</div>
32+
<div data-key="72" class="key">
33+
<kbd>H</kbd>
34+
<span class="sound">ride</span>
35+
</div>
36+
<div data-key="74" class="key">
37+
<kbd>J</kbd>
38+
<span class="sound">snare</span>
39+
</div>
40+
<div data-key="75" class="key">
41+
<kbd>K</kbd>
42+
<span class="sound">tom</span>
43+
</div>
44+
<div data-key="76" class="key">
45+
<kbd>L</kbd>
46+
<span class="sound">tink</span>
47+
</div>
2448
</div>
25-
<footer style="margin-top: 50px;">
26-
<p>Made with ❤️ by @AdishiSood</p>
27-
</footer>
28-
<script src="index.js"></script>
29-
</body>
3049

50+
<audio data-key="65" src="https://res.cloudinary.com/adishisood/video/upload/v1618602171/clap_wav.wav"></audio>
51+
<audio data-key="83" src="https://res.cloudinary.com/adishisood/video/upload/v1618602171/hihat_wav.wav"></audio>
52+
<audio data-key="68" src="https://res.cloudinary.com/adishisood/video/upload/v1618602170/kick_wav.wav"></audio>
53+
<audio data-key="70" src="https://res.cloudinary.com/adishisood/video/upload/v1618602171/openhat_wav.wav"></audio>
54+
<audio data-key="71" src="https://res.cloudinary.com/adishisood/video/upload/v1618602172/boom_wav.wav"></audio>
55+
<audio data-key="72" src="https://res.cloudinary.com/adishisood/video/upload/v1618602172/ride_wav.wav"></audio>
56+
<audio data-key="74" src="https://res.cloudinary.com/adishisood/video/upload/v1618602170/snare_wav.wav"></audio>
57+
<audio data-key="75" src="https://res.cloudinary.com/adishisood/video/upload/v1618602170/tom_wav.wav"></audio>
58+
<audio data-key="76" src="https://res.cloudinary.com/adishisood/video/upload/v1618602170/tink_wav.wav"></audio>
59+
60+
<script>
61+
62+
function removeTransition(e) {
63+
if (e.propertyName !== 'transform') return;
64+
e.target.classList.remove('playing');
65+
}
66+
67+
function playSound(e) {
68+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
69+
const key = document.querySelector(`div[data-key="${e.keyCode}"]`);
70+
if (!audio) return;
71+
72+
key.classList.add('playing');
73+
audio.currentTime = 0;
74+
audio.play();
75+
}
76+
77+
const keys = Array.from(document.querySelectorAll('.key'));
78+
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
79+
window.addEventListener('keydown', playSound);
80+
81+
</script>
82+
</body>
3183
</html>

0 commit comments

Comments
 (0)