Skip to content

Commit 87cabff

Browse files
committed
Adds scripts.js and style.css
I wanted a more segmented workspace that reflects my current workflows
1 parent a016dc7 commit 87cabff

3 files changed

Lines changed: 85 additions & 65 deletions

File tree

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: 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);

02 - JS and CSS Clock/style.css

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}

0 commit comments

Comments
 (0)