-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
67 lines (66 loc) · 1.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!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>Stage Progress Bar</title>
<style>
.progress {
width: 600px;
}
.progress-fill {
width: 0;
height: 10px;
border-radius: 10px;
background: #009578;
transition: width 0.5s;
}
.progress-text {
padding: 10px;
text-align: center;
color: #777;
font-size: 2rem;
font-style: italic;
font-family: sans-serif;
}
</style>
</head>
<body>
<div class="progress" id="myProgressBar">
<div class="progress-fill"></div>
<div
class="progress-text"
data-stages="0:Initial Setup,25:Drinking Water,50:Calculating,75:Making build,20:Loading assets,100:Done!"
></div>
</div>
<script>
function updateProgressBar(progressBar, value) {
const progressFill = progressBar.querySelector('.progress-fill');
const progressText = progressBar.querySelector('.progress-text');
const stages = progressText.dataset.stages
.split(',')
.map(stage => stage.split(':'));
stages.sort((stageA, stageB) => {
return stageB[0] - stageA[0];
});
const activeStage = stages.find(stage => {
return value >= stage[0];
});
progressFill.style.width = `${value}%`;
progressText.textContent =
value !== 100
? `${value}% - ${activeStage[1]}...`
: `${value}% - ${activeStage[1]}`;
}
let i = 0;
let timerId = setInterval(() => {
updateProgressBar(document.getElementById('myProgressBar'), i);
i++;
if (i > 100) {
clearInterval(timerId);
}
}, 100);
</script>
</body>
</html>