Skip to content

Commit 40ae71d

Browse files
Drumkit and Clock projects
0 parents  commit 40ae71d

File tree

13 files changed

+229
-0
lines changed

13 files changed

+229
-0
lines changed

clock/index.html

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>JS + CSS Clock</title>
6+
</head>
7+
<body>
8+
9+
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+
transform-origin: 100%;
66+
transform: rotate(90deg);
67+
transition: all 0.05s;
68+
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
69+
}
70+
71+
</style>
72+
73+
<script>
74+
const secondHand = document.querySelector('.second-hand');
75+
const minuteHand = document.querySelector('.min-hand');
76+
const hourHand = document.querySelector('.hour-hand');
77+
function setDate() {
78+
const now = new Date();
79+
const seconds = now.getSeconds();
80+
const secondsDegrees = ((seconds / 60) * 360) + 90;
81+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
82+
83+
const minutes = now.getMinutes();
84+
const minutesDegrees = ((minutes / 60) * 360) + 90;
85+
minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;
86+
87+
const hours = now.getHours();
88+
const hoursDegrees = ((hours / 12) * 360 ) + 90;
89+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
90+
}
91+
92+
setInterval(setDate, 1000);
93+
94+
</script>
95+
</body>
96+
</html>

drumkit/.DS_Store

6 KB
Binary file not shown.

drumkit/index.html

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<!DOCTYPE html>
2+
<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>
9+
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>
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+
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+
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;
65+
//Rewind to start
66+
audio.currentTime = 0;
67+
audio.play();
68+
key.classList.add('playing');
69+
}
70+
function removeTransition(e) {
71+
if(e.propertyName !== 'transform') return;
72+
this.classList.remove('playing');
73+
}
74+
75+
const keys = document.querySelectorAll('.key');
76+
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
77+
window.addEventListener('keydown', playSound);
78+
79+
</script>
80+
81+
82+
</body>
83+
</html>

drumkit/sounds/boom.wav

130 KB
Binary file not shown.

drumkit/sounds/clap.wav

63.4 KB
Binary file not shown.

drumkit/sounds/hihat.wav

50.9 KB
Binary file not shown.

drumkit/sounds/kick.wav

15.2 KB
Binary file not shown.

drumkit/sounds/openhat.wav

238 KB
Binary file not shown.

drumkit/sounds/ride.wav

429 KB
Binary file not shown.

drumkit/sounds/snare.wav

32.6 KB
Binary file not shown.

drumkit/sounds/tink.wav

5.32 KB
Binary file not shown.

drumkit/sounds/tom.wav

105 KB
Binary file not shown.

drumkit/style.css

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
html {
2+
font-size: 10px;
3+
background: url(http://i.imgur.com/b9r5sEL.jpg) bottom center;
4+
background-size: cover;
5+
}
6+
body,html {
7+
margin: 0;
8+
padding: 0;
9+
font-family: sans-serif;
10+
}
11+
12+
.keys {
13+
display: flex;
14+
flex: 1;
15+
min-height: 100vh;
16+
align-items: center;
17+
justify-content: center;
18+
}
19+
20+
.key {
21+
border: .4rem solid black;
22+
border-radius: .5rem;
23+
margin: 1rem;
24+
font-size: 1.5rem;
25+
padding: 1rem .5rem;
26+
transition: all .07s ease;
27+
width: 10rem;
28+
text-align: center;
29+
color: white;
30+
background: rgba(0,0,0,0.4);
31+
text-shadow: 0 0 .5rem black;
32+
}
33+
34+
.playing {
35+
transform: scale(1.2);
36+
border-color: #ffc600;
37+
box-shadow: 0 0 1rem #ffc600;
38+
}
39+
40+
kbd {
41+
display: block;
42+
font-size: 4rem;
43+
}
44+
45+
.sound {
46+
font-size: 1.2rem;
47+
text-transform: uppercase;
48+
letter-spacing: .1rem;
49+
color: #ffc600;
50+
}

0 commit comments

Comments
 (0)