Skip to content

Commit fe40b5a

Browse files
committed
add incrementing counter
1 parent eb5920f commit fe40b5a

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

13-random choice picker/style.css

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ textarea {
3737
font-size: 16px;
3838
}
3939

40+
textarea:focus {
41+
outline: 0;
42+
}
43+
4044
.tag {
4145
background-color: #f0932b;
4246
color: #fff;

15-incrementing counter/index.html

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<link
7+
rel="stylesheet"
8+
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css"
9+
integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA=="
10+
crossorigin="anonymous"
11+
/>
12+
<link rel="stylesheet" href="style.css" />
13+
<title>Increment Counter</title>
14+
</head>
15+
<body>
16+
<div class="counter-container">
17+
<i class="fab fa-instagram fa-3x"></i>
18+
<div class="counter" data-target="12000"></div>
19+
<span>Instagram Followers</span>
20+
</div>
21+
<div class="counter-container">
22+
<i class="fab fa-youtube fa-3x"></i>
23+
<div class="counter" data-target="5000"></div>
24+
<span>YouTube Subscribers</span>
25+
</div>
26+
<div class="counter-container">
27+
<i class="fab fa-facebook fa-3x"></i>
28+
<div class="counter" data-target="7500"></div>
29+
<span>Facebook Fans</span>
30+
</div>
31+
<script src="script.js"></script>
32+
</body>
33+
</html>

15-incrementing counter/script.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const counters = document.querySelectorAll(".counter");
2+
3+
counters.forEach((counter) => {
4+
counter.innerText = "0";
5+
const updateCounter = () => {
6+
const target = +counter.getAttribute("data-target");
7+
const count = +counter.innerText;
8+
const increment = target / 200;
9+
if (count < target) {
10+
counter.innerText = `${Math.ceil(count + increment)}`;
11+
setTimeout(updateCounter, 1);
12+
} else counter.innerText = target;
13+
};
14+
updateCounter();
15+
});

15-incrementing counter/style.css

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@import url("https://fonts.googleapis.com/css2?family=Roboto+Mono&display=swap");
2+
3+
* {
4+
box-sizing: border-box;
5+
}
6+
7+
body {
8+
background-color: #8e44ad;
9+
color: #fff;
10+
font-family: "Roboto Mono", sans-serif;
11+
display: flex;
12+
align-items: center;
13+
justify-content: center;
14+
height: 100vh;
15+
overflow: hidden;
16+
margin: 0;
17+
}
18+
19+
.counter-container {
20+
display: flex;
21+
flex-direction: column;
22+
justify-content: center;
23+
text-align: center;
24+
margin: 30px 50px;
25+
}
26+
27+
.counter {
28+
font-size: 60px;
29+
margin-top: 10px;
30+
}
31+
32+
@media (max-width: 580px) {
33+
body {
34+
flex-direction: column;
35+
}
36+
}

0 commit comments

Comments
 (0)