Skip to content

Commit ce22fc5

Browse files
committed
2 parents 3024474 + 830a613 commit ce22fc5

File tree

6 files changed

+176
-139
lines changed

6 files changed

+176
-139
lines changed
File renamed without changes.

01 - JavaScript Drum Kit/index-START.html renamed to 01 - JavaScript Drum Kit/index-files/index.html

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,25 @@
5959

6060
<script>
6161

62-
</script>
6362

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 all together
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);
79+
80+
</script>
6481

6582
</body>
6683
</html>
Lines changed: 73 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,81 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8">
5-
<title>JS Drum Kit</title>
6-
<link rel="stylesheet" href="style.css">
7-
</head>
8-
<body>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>JS Drum Kit</title>
6+
<link rel="stylesheet" href="style.css">
7+
</head>
8+
<body>
99

10-
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>
10+
<div class="keys">
11+
<div data-key="65" class="key">
12+
<kbd>A</kbd>
13+
<span class="sound">clap</span>
14+
</div>
15+
<div data-key="83" class="key">
16+
<kbd>S</kbd>
17+
<span class="sound">hihat</span>
18+
</div>
19+
<div data-key="68" class="key">
20+
<kbd>D</kbd>
21+
<span class="sound">kick</span>
22+
</div>
23+
<div data-key="70" class="key">
24+
<kbd>F</kbd>
25+
<span class="sound">openhat</span>
26+
</div>
27+
<div data-key="71" class="key">
28+
<kbd>G</kbd>
29+
<span class="sound">boom</span>
30+
</div>
31+
<div data-key="72" class="key">
32+
<kbd>H</kbd>
33+
<span class="sound">ride</span>
34+
</div>
35+
<div data-key="74" class="key">
36+
<kbd>J</kbd>
37+
<span class="sound">snare</span>
38+
</div>
39+
<div data-key="75" class="key">
40+
<kbd>K</kbd>
41+
<span class="sound">tom</span>
42+
</div>
43+
<div data-key="76" class="key">
44+
<kbd>L</kbd>
45+
<span class="sound">tink</span>
46+
</div>
3947
</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>
48-
</div>
49-
50-
<audio data-key="65" src="sounds/clap.wav"></audio>
51-
<audio data-key="83" src="sounds/hihat.wav"></audio>
52-
<audio data-key="68" src="sounds/kick.wav"></audio>
53-
<audio data-key="70" src="sounds/openhat.wav"></audio>
54-
<audio data-key="71" src="sounds/boom.wav"></audio>
55-
<audio data-key="72" src="sounds/ride.wav"></audio>
56-
<audio data-key="74" src="sounds/snare.wav"></audio>
57-
<audio data-key="75" src="sounds/tom.wav"></audio>
58-
<audio data-key="76" src="sounds/tink.wav"></audio>
59-
60-
<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 all together
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-
}
7548

76-
const keys = document.querySelectorAll('.key');
77-
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
78-
window.addEventListener('keydown', playSound);
49+
<audio data-key="65" src="sounds/clap.wav"></audio>
50+
<audio data-key="83" src="sounds/hihat.wav"></audio>
51+
<audio data-key="68" src="sounds/kick.wav"></audio>
52+
<audio data-key="70" src="sounds/openhat.wav"></audio>
53+
<audio data-key="71" src="sounds/boom.wav"></audio>
54+
<audio data-key="72" src="sounds/ride.wav"></audio>
55+
<audio data-key="74" src="sounds/snare.wav"></audio>
56+
<audio data-key="75" src="sounds/tom.wav"></audio>
57+
<audio data-key="76" src="sounds/tink.wav"></audio>
7958

80-
</script>
59+
<script>
60+
window.addEventListener('keydown', playSound);
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 there's no keyval.
65+
if (!audio)
66+
return;
8167

82-
</body>
68+
audio.currentTime = 0;
69+
audio.play();
70+
key.classList.add('playing');
71+
}
72+
function removedTransition(e) {
73+
if(e.propertyName !== 'transform') return;
74+
this.classList.remove('playing');
75+
console.log(e);
76+
}
77+
const keys = document.querySelectorAll('.key');
78+
keys.forEach(key => key.addEventListener('transitionend', removedTransition));
79+
</script>
80+
</body>
8381
</html>

02 - JS + CSS Clock/index.html

Lines changed: 59 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -16,81 +16,80 @@
1616
</div>
1717

1818

19-
<style>
20-
html {
21-
background:#018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
22-
background-size:cover;
23-
font-family:'helvetica neue';
24-
text-align: center;
25-
font-size: 10px;
26-
}
19+
<style>
20+
html {
21+
background:#018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
22+
background-size:cover;
23+
font-family:'helvetica neue';
24+
text-align: center;
25+
font-size: 10px;
26+
}
2727

28-
body {
29-
font-size: 2rem;
30-
display:flex;
31-
flex:1;
32-
min-height: 100vh;
33-
align-items: center;
34-
}
28+
body {
29+
font-size: 2rem;
30+
display:flex;
31+
flex:1;
32+
min-height: 100vh;
33+
align-items: center;
34+
}
3535

36-
.clock {
37-
width: 30rem;
38-
height: 30rem;
39-
border:20px solid white;
40-
border-radius:50%;
41-
margin:50px auto;
42-
position: relative;
43-
padding:2rem;
44-
box-shadow:
45-
0 0 0 4px rgba(0,0,0,0.1),
46-
inset 0 0 0 3px #EFEFEF,
47-
inset 0 0 10px black,
48-
0 0 10px rgba(0,0,0,0.2);
49-
}
36+
.clock {
37+
width: 30rem;
38+
height: 30rem;
39+
border:20px solid white;
40+
border-radius:50%;
41+
margin:50px auto;
42+
position: relative;
43+
padding:2rem;
44+
box-shadow:
45+
0 0 0 4px rgba(0,0,0,0.1),
46+
inset 0 0 0 3px #EFEFEF,
47+
inset 0 0 10px black,
48+
0 0 10px rgba(0,0,0,0.2);
49+
}
5050

51-
.clock-face {
52-
position: relative;
53-
width: 100%;
54-
height: 100%;
55-
transform: translateY(-3px); /* account for the height of the clock hands */
56-
}
51+
.clock-face {
52+
position: relative;
53+
width: 100%;
54+
height: 100%;
55+
transform: translateY(-3px); /* account for the height of the clock hands */
56+
}
5757

58-
.hand {
59-
width:50%;
60-
height:6px;
61-
background:black;
62-
position: absolute;
63-
top:50%;
64-
transform-origin: 100%;
65-
transform: rotate(90deg);
66-
transition: all 0.05s;
67-
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
68-
}
69-
</style>
70-
71-
<script>
58+
.hand {
59+
width:50%;
60+
height:6px;
61+
background:black;
62+
position: absolute;
63+
top:50%;
64+
transform-origin: 100%;
65+
transform: rotate(90deg);
66+
transition: all 0.05s;
67+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
68+
}
69+
</style>
70+
<script>
7271
const secondHand = document.querySelector('.second-hand');
73-
const minsHand = document.querySelector('.min-hand');
72+
const minuteHand = document.querySelector('.min-hand');
7473
const hourHand = document.querySelector('.hour-hand');
7574

7675
function setDate() {
7776
const now = new Date();
78-
7977
const seconds = now.getSeconds();
80-
const secondsDegrees = ((seconds / 60) * 360) + 90;
81-
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
78+
const minutes = now.getMinutes();
79+
const hours = now.getHours();
8280

83-
const mins = now.getMinutes();
84-
const minsDegrees = ((mins / 60) * 360) + 90;
85-
minsHand.style.transform = `rotate(${minsDegrees}deg)`;
81+
console.log(minutes, hours);
82+
const secondsDegrees = ((seconds / 60) * 360) + 90;
83+
const minutesDegrees = ((minutes / 60) * 360) + 90;
84+
const hoursDegrees = ((hours / 60) * 360) + 90;
8685

87-
const hour = now.getMinutes();
88-
const hourDegrees = ((mins / 12) * 360) + 90;
89-
hourHand.style.transform = `rotate(${hourDegrees}deg)`;
86+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
87+
minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;
88+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
9089
}
9190

9291
setInterval(setDate, 1000);
9392

94-
</script>
93+
</script>
9594
</body>
9695
</html>
File renamed without changes.
Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,36 @@
6161
background:black;
6262
position: absolute;
6363
top:50%;
64+
transform-origin: 100%;
65+
transform: rotate(90deg);
66+
transition: all 0.05s;
67+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
6468
}
69+
</style>
6570

66-
</style>
71+
<script>
72+
const secondHand = document.querySelector('.second-hand');
73+
const minsHand = document.querySelector('.min-hand');
74+
const hourHand = document.querySelector('.hour-hand');
6775

68-
<script>
76+
function setDate() {
77+
const now = new Date();
6978

79+
const seconds = now.getSeconds();
80+
const secondsDegrees = ((seconds / 60) * 360) + 90;
81+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
7082

71-
</script>
83+
const mins = now.getMinutes();
84+
const minsDegrees = ((mins / 60) * 360) + 90;
85+
minsHand.style.transform = `rotate(${minsDegrees}deg)`;
86+
87+
const hour = now.getMinutes();
88+
const hourDegrees = ((mins / 12) * 360) + 90;
89+
hourHand.style.transform = `rotate(${hourDegrees}deg)`;
90+
}
91+
92+
setInterval(setDate, 1000);
93+
94+
</script>
7295
</body>
7396
</html>

0 commit comments

Comments
 (0)