Skip to content

Commit a14b251

Browse files
committed
0427 Day1 completed
1 parent 6559518 commit a14b251

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed
-853 KB
Binary file not shown.

01 - JavaScript Drum Kit/index-START.html

+19
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,26 @@
5858
<audio data-key="76" src="sounds/tink.wav"></audio>
5959

6060
<script>
61+
function playSound(e) {
62+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
63+
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
64+
if(!audio) return; //stop function
65+
// console.log(key);
66+
audio.currentTime = 0;
67+
audio.play();
68+
key.classList.add('playing');
69+
}
6170

71+
function removeTransition(e) {
72+
if (e.propertyName !== 'transform') return; //skip it if it's not a transition
73+
// this.classList.remove("playing");
74+
e.target.classList.remove("playing");
75+
}
76+
77+
const keys = document.querySelectorAll('.key')
78+
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
79+
80+
window.addEventListener('keydown', playSound);
6281
</script>
6382

6483

01 - JavaScript Drum Kit/style.css

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
html {
22
font-size: 10px;
3-
background: url('./background.jpg') bottom center;
3+
/* background: url('./background.jpg') bottom center; */
44
background-size: cover;
55
}
66

7-
body,html {
7+
body,
8+
html {
89
margin: 0;
910
padding: 0;
1011
font-family: sans-serif;
@@ -19,17 +20,17 @@ body,html {
1920
}
2021

2122
.key {
22-
border: .4rem solid black;
23-
border-radius: .5rem;
23+
border: 0.4rem solid black;
24+
border-radius: 0.5rem;
2425
margin: 1rem;
2526
font-size: 1.5rem;
26-
padding: 1rem .5rem;
27-
transition: all .07s ease;
27+
padding: 1rem 0.5rem;
28+
transition: all 0.07s ease;
2829
width: 10rem;
2930
text-align: center;
3031
color: white;
31-
background: rgba(0,0,0,0.4);
32-
text-shadow: 0 0 .5rem black;
32+
background: rgba(0, 0, 0, 0.4);
33+
text-shadow: 0 0 0.5rem black;
3334
}
3435

3536
.playing {
@@ -46,6 +47,6 @@ kbd {
4647
.sound {
4748
font-size: 1.2rem;
4849
text-transform: uppercase;
49-
letter-spacing: .1rem;
50+
letter-spacing: 0.1rem;
5051
color: #ffc600;
5152
}

0 commit comments

Comments
 (0)