Skip to content

Commit fc7d911

Browse files
committed
Finished day wesbos#1
1 parent 508e476 commit fc7d911

File tree

3 files changed

+31
-92
lines changed

3 files changed

+31
-92
lines changed

01 - JavaScript Drum Kit/index-START.html

Lines changed: 0 additions & 66 deletions
This file was deleted.

01 - JavaScript Drum Kit/index-FINISHED.html renamed to 01 - JavaScript Drum Kit/index.html

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
45
<meta charset="UTF-8">
56
<title>JS Drum Kit</title>
67
<link rel="stylesheet" href="style.css">
78
</head>
9+
810
<body>
911

1012

@@ -57,27 +59,29 @@
5759
<audio data-key="75" src="sounds/tom.wav"></audio>
5860
<audio data-key="76" src="sounds/tink.wav"></audio>
5961

60-
<script>
61-
function removeTransition(e) {
62-
if (e.propertyName !== 'transform') return;
63-
e.target.classList.remove('playing');
64-
}
62+
<script>
63+
function playSound(e) {
64+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
65+
if (!audio) return;
66+
audio.currentTime = 0;
67+
audio.play();
6568

66-
function playSound(e) {
67-
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
68-
const key = document.querySelector(`div[data-key="${e.keyCode}"]`);
69-
if (!audio) return;
69+
// Add key styling
70+
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
71+
key.classList.add('playing');
72+
}
7073

71-
key.classList.add('playing');
72-
audio.currentTime = 0;
73-
audio.play();
74-
}
74+
function removeTransition(e) {
75+
if (e.propertyName !== 'transform') return;
76+
this.classList.remove('playing'); // 'this' is the key
77+
}
7578

76-
const keys = Array.from(document.querySelectorAll('.key'));
77-
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
78-
window.addEventListener('keydown', playSound);
79-
</script>
79+
const keys = document.querySelectorAll('.key');
80+
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
81+
window.addEventListener('keydown', playSound);
82+
</script>
8083

8184

8285
</body>
83-
</html>
86+
87+
</html>

01 - JavaScript Drum Kit/style.css

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ html {
33
background: url(http://i.imgur.com/b9r5sEL.jpg) bottom center;
44
background-size: cover;
55
}
6-
body,html {
6+
body,
7+
html {
78
margin: 0;
89
padding: 0;
910
font-family: sans-serif;
@@ -18,17 +19,17 @@ body,html {
1819
}
1920

2021
.key {
21-
border: .4rem solid black;
22-
border-radius: .5rem;
22+
border: 0.4rem solid black;
23+
border-radius: 0.5rem;
2324
margin: 1rem;
2425
font-size: 1.5rem;
25-
padding: 1rem .5rem;
26-
transition: all .07s ease;
26+
padding: 1rem 0.5rem;
27+
transition: all 0.07s ease;
2728
width: 10rem;
2829
text-align: center;
2930
color: white;
30-
background: rgba(0,0,0,0.4);
31-
text-shadow: 0 0 .5rem black;
31+
background: rgba(0, 0, 0, 0.4);
32+
text-shadow: 0 0 0.5rem black;
3233
}
3334

3435
.playing {
@@ -45,6 +46,6 @@ kbd {
4546
.sound {
4647
font-size: 1.2rem;
4748
text-transform: uppercase;
48-
letter-spacing: .1rem;
49+
letter-spacing: 0.1rem;
4950
color: #ffc600;
5051
}

0 commit comments

Comments
 (0)