Add files via upload
This commit is contained in:
parent
65f5bf0c7e
commit
47ca543836
20
100_projects/74-visual-counter/inedx.html
Normal file
20
100_projects/74-visual-counter/inedx.html
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="counter" data-target="20000"></div>
|
||||
<span>Followers Counter</span>
|
||||
<div class="counter" data-target="5000"></div>
|
||||
<span>Subscribers Counter</span>
|
||||
|
||||
|
||||
<script src="main.js"></script>
|
||||
</body>
|
||||
</html>
|
23
100_projects/74-visual-counter/main.js
Normal file
23
100_projects/74-visual-counter/main.js
Normal file
@ -0,0 +1,23 @@
|
||||
const counters = document.querySelectorAll('.counter');
|
||||
|
||||
// this could work for multiple counters
|
||||
counters.forEach(counter => {
|
||||
// start with 0 by default
|
||||
counter.innerText = '0';
|
||||
|
||||
const updateCounter = () => {
|
||||
const target = +counter.getAttribute('data-target');
|
||||
const c = +counter.innerText;
|
||||
|
||||
// get the 0.1% to speed up things
|
||||
const increment = target / 2000;
|
||||
|
||||
if(c < target) {
|
||||
counter.innerText = `${Math.ceil(c + increment)}`;
|
||||
setTimeout(updateCounter, 1)
|
||||
} else {
|
||||
counter.innerText = target;
|
||||
}
|
||||
};
|
||||
updateCounter();
|
||||
});
|
20
100_projects/74-visual-counter/style.css
Normal file
20
100_projects/74-visual-counter/style.css
Normal file
@ -0,0 +1,20 @@
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
background-color: #8FBC8F;
|
||||
color: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
margin: 0;
|
||||
}
|
||||
.counter {
|
||||
font-size: 60px;
|
||||
margin-top: 30px;
|
||||
}
|
||||
span{
|
||||
font-size: 24px;
|
||||
}
|
Loading…
Reference in New Issue
Block a user