Skip to content

Commit b2a8914

Browse files
authored
Update index.html
1 parent d124b95 commit b2a8914

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

01 - JavaScript Drum Kit/index.html

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
</head>
88
<body>
99

10-
10+
<!-- Buttons -->
11+
<!-- Data attributes (data-key) wire up buttons with sounds -->
1112
<div class="keys">
1213
<div data-key="65" class="key">
1314
<kbd>A</kbd>
@@ -47,6 +48,7 @@
4748
</div>
4849
</div>
4950

51+
<!-- Links to sound files that play on button press -->
5052
<audio data-key="65" src="sounds/clap.wav"></audio>
5153
<audio data-key="83" src="sounds/hihat.wav"></audio>
5254
<audio data-key="68" src="sounds/kick.wav"></audio>
@@ -58,26 +60,12 @@
5860
<audio data-key="76" src="sounds/tink.wav"></audio>
5961

6062
<script>
61-
62-
63-
function playSound(e) {
64-
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
65-
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
66-
if (!audio) return; // stop the function from running altogether
67-
audio.currentTime = 0; // rewind to the start
68-
audio.play();
69-
key.classList.add('playing');
70-
}
71-
function removeTransition(e) {
72-
if (e.propertyName !== 'transform') return; // skip it if it's not a transform
73-
this.classList.remove('playing');
74-
}
75-
76-
const keys = document.querySelectorAll('.key');
77-
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
78-
window.addEventListener('keydown', playSound);
63+
window.addEventListener('keydown', function (e) {
64+
console.log(e);
65+
});
7966

8067
</script>
8168

69+
8270
</body>
8371
</html>

0 commit comments

Comments
 (0)