Skip to content

Commit d09ac9a

Browse files
authored
Merge pull request #1 from dustinleer/completed
Completed
2 parents 7d8289c + a7b65f0 commit d09ac9a

File tree

9 files changed

+250
-157
lines changed

9 files changed

+250
-157
lines changed

01 - JavaScript Drum Kit/index-START.html

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,64 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<meta charset="UTF-8">
5-
<title>JS Drum Kit</title>
6-
<link rel="stylesheet" href="style.css">
4+
<meta charset="UTF-8">
5+
<title>JS Drum Kit</title>
6+
<link rel="stylesheet" href="style.css">
77
</head>
88
<body>
99

10+
<div class="keys">
11+
<div class="keywrap">
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>
48+
</div>
49+
</div>
1050

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>
48-
</div>
51+
<audio data-key="65" src="sounds/clap.wav"></audio>
52+
<audio data-key="83" src="sounds/hihat.wav"></audio>
53+
<audio data-key="68" src="sounds/kick.wav"></audio>
54+
<audio data-key="70" src="sounds/openhat.wav"></audio>
55+
<audio data-key="71" src="sounds/boom.wav"></audio>
56+
<audio data-key="72" src="sounds/ride.wav"></audio>
57+
<audio data-key="74" src="sounds/snare.wav"></audio>
58+
<audio data-key="75" src="sounds/tom.wav"></audio>
59+
<audio data-key="76" src="sounds/tink.wav"></audio>
4960

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-
</script>
61+
<script type="text/javascript" src="scripts.js"></script>
6362

6463

6564
</body>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/********************************************
2+
* Call functions on Window Event Listener
3+
********************************************/
4+
function playSound(e) {
5+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
6+
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
7+
8+
// stop the function from running all together
9+
if (!audio) return;
10+
11+
// Rewinds audio file to start
12+
audio.currentTime = 0;
13+
14+
// Plays audio file
15+
audio.play();
16+
key.classList.add('playing');
17+
}
18+
19+
function removeTransition(e) {
20+
// skip if it's not a transform
21+
if(e.propertyName !== 'transform') return;
22+
this.classList.remove('playing');
23+
}
24+
25+
const keys = document.querySelectorAll('.key');
26+
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
27+
28+
window.addEventListener('keydown', playSound);

01 - JavaScript Drum Kit/style.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,14 @@ kbd {
4949
letter-spacing: .1rem;
5050
color: #ffc600;
5151
}
52+
53+
.keywrap {
54+
display: flex;
55+
justify-content: center;
56+
}
57+
58+
@media (max-width: 950px) {
59+
.keywrap {
60+
flex-wrap: wrap;
61+
}
62+
}
Lines changed: 11 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,20 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<meta charset="UTF-8">
5-
<title>JS + CSS Clock</title>
4+
<meta charset="UTF-8">
5+
<title>JS + CSS Clock</title>
6+
<link rel="stylesheet" href="style.css">
67
</head>
78
<body>
89

10+
<div class="clock">
11+
<div class="clock-face">
12+
<div class="hand hour-hand"></div>
13+
<div class="hand min-hand"></div>
14+
<div class="hand second-hand"></div>
15+
</div>
16+
</div>
917

10-
<div class="clock">
11-
<div class="clock-face">
12-
<div class="hand hour-hand"></div>
13-
<div class="hand min-hand"></div>
14-
<div class="hand second-hand"></div>
15-
</div>
16-
</div>
17-
18-
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-
}
27-
28-
body {
29-
margin: 0;
30-
font-size: 2rem;
31-
display: flex;
32-
flex: 1;
33-
min-height: 100vh;
34-
align-items: center;
35-
}
36-
37-
.clock {
38-
width: 30rem;
39-
height: 30rem;
40-
border: 20px solid white;
41-
border-radius: 50%;
42-
margin: 50px auto;
43-
position: relative;
44-
padding: 2rem;
45-
box-shadow:
46-
0 0 0 4px rgba(0,0,0,0.1),
47-
inset 0 0 0 3px #EFEFEF,
48-
inset 0 0 10px black,
49-
0 0 10px rgba(0,0,0,0.2);
50-
}
51-
52-
.clock-face {
53-
position: relative;
54-
width: 100%;
55-
height: 100%;
56-
transform: translateY(-3px); /* account for the height of the clock hands */
57-
}
58-
59-
.hand {
60-
width: 50%;
61-
height: 6px;
62-
background: black;
63-
position: absolute;
64-
top: 50%;
65-
}
66-
67-
</style>
68-
69-
<script>
70-
71-
72-
</script>
18+
<script type="text/javascript" src="scripts.js"></script>
7319
</body>
7420
</html>

02 - JS and CSS Clock/scripts.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/********************************************
2+
* Call functions on Window Event Listener
3+
********************************************/
4+
const secondHand = document.querySelector('.second-hand');
5+
const minsHand = document.querySelector('.min-hand');
6+
const hourHand = document.querySelector('.hour-hand');
7+
8+
9+
function setDate() {
10+
const now = new Date();
11+
const seconds = now.getSeconds();
12+
const secondsDegrees = ((seconds / 60) * 360) + 90;
13+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
14+
// console.log(seconds);
15+
16+
const mins = now.getMinutes();
17+
const minsDegrees = ((mins / 60) * 360) + 90;
18+
minsHand.style.transform = `rotate(${minsDegrees}deg)`;
19+
// console.log(minutes);
20+
21+
const hours = now.getHours();
22+
const hoursDegrees = ((hours / 12) * 360) + 90;
23+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
24+
// console.log(hours);
25+
26+
}
27+
setInterval(setDate, 1000);

02 - JS and CSS Clock/style.css

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
html {
2+
background: #018DED url(http://unsplash.it/1500/1000?image=881&blur=50);
3+
background-size: cover;
4+
font-family: 'helvetica neue';
5+
text-align: center;
6+
font-size: 10px;
7+
}
8+
9+
body {
10+
margin: 0;
11+
font-size: 2rem;
12+
display: flex;
13+
flex: 1;
14+
min-height: 100vh;
15+
align-items: center;
16+
}
17+
18+
.clock {
19+
width: 30rem;
20+
height: 30rem;
21+
border: 20px solid white;
22+
border-radius: 50%;
23+
margin: 50px auto;
24+
position: relative;
25+
padding: 2rem;
26+
box-shadow:
27+
0 0 0 4px rgba(0,0,0,0.1),
28+
inset 0 0 0 3px #EFEFEF,
29+
inset 0 0 10px black,
30+
0 0 10px rgba(0,0,0,0.2);
31+
}
32+
33+
.clock-face {
34+
position: relative;
35+
width: 100%;
36+
height: 100%;
37+
transform: translateY(-3px); /* account for the height of the clock hands */
38+
}
39+
40+
.hand {
41+
width: 50%;
42+
height: 6px;
43+
background: black;
44+
position: absolute;
45+
top: 50%;
46+
transform-origin: 100%;
47+
transform: rotate(90deg);
48+
transition: all 0.05s;
49+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1)
50+
}
Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,27 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<meta charset="UTF-8">
5-
<title>Scoped CSS Variables and JS</title>
4+
<meta charset="UTF-8">
5+
<title>Scoped CSS Variables and JS</title>
6+
<link rel="stylesheet" href="style.css">
67
</head>
78
<body>
8-
<h2>Update CSS Variables with <span class='hl'>JS</span></h2>
9+
<h2>Update CSS Variables with <span class='hl'>JS</span></h2>
910

10-
<div class="controls">
11-
<label for="spacing">Spacing:</label>
12-
<input id="spacing" type="range" name="spacing" min="10" max="200" value="10" data-sizing="px">
11+
<div class="controls">
12+
<label for="spacing">Spacing:</label>
13+
<input id="spacing" type="range" name="spacing" min="10" max="200" value="10" data-sizing="px">
1314

14-
<label for="blur">Blur:</label>
15-
<input id="blur" type="range" name="blur" min="0" max="25" value="10" data-sizing="px">
15+
<label for="blur">Blur:</label>
16+
<input id="blur" type="range" name="blur" min="0" max="25" value="10" data-sizing="px">
1617

17-
<label for="base">Base Color</label>
18-
<input id="base" type="color" name="base" value="#ffc600">
19-
</div>
18+
<label for="base">Base Color</label>
19+
<input id="base" type="color" name="base" value="#ffc600">
20+
</div>
2021

21-
<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">
22+
<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">
2223

23-
<style>
24-
25-
/*
26-
misc styles, nothing to do with CSS variables
27-
*/
28-
29-
body {
30-
text-align: center;
31-
background: #193549;
32-
color: white;
33-
font-family: 'helvetica neue', sans-serif;
34-
font-weight: 100;
35-
font-size: 50px;
36-
}
37-
38-
.controls {
39-
margin-bottom: 50px;
40-
}
41-
42-
input {
43-
width: 100px;
44-
}
45-
</style>
46-
47-
<script>
48-
</script>
24+
<script type="text/javascript" src="scripts.js"></script>
4925

5026
</body>
5127
</html>

0 commit comments

Comments
 (0)