-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
171 lines (150 loc) · 3.39 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!DOCTYPE html>
<html>
<head>
<title>Progress</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- <meta http-equiv="refresh" content="2"> -->
</head>
<body>
<h2>Progress bar for task completion</h2>
<div class="cont">
<div class="loader">
<label class="counter">Profile is <span>0%</span> complete</label>
</div>
</div>
<p>
<h4 style="text-decoration: underline;">Sample form data</h4>
<code>const <b>details</b> = {<br>
name: "Jefferson",<br>
age: 12,<br>
weight: 70,<br>
level: 30,<br>
relationship: "",<br>
contact: "",<br>
email: "",<br>
friends: 459 <br>
}</code><br>
Each filled field has a mark attached to it. The total mark is equal to the total length of the progress bar [100%].
<br>
<h3>Each field is equal to - 100% / Length of object(converted to array)</h3>
</p>
<style type="text/css">
body{
background: #f2f2f2;
font-family: Nunito;
padding: 10px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.cont{
margin-top: 30px;
height: 20px;
width: 100%;
background: rgba(0, 200, 0, .3);
border-radius: 50px;
}
.cont .loader{
height: 20px;
position: relative;
box-sizing: border-box;
width: 0%;
background: rgba(0, 200, 0, .8);
border-radius: 50px;
transition: width 1.5s linear
}
.cont .loader:before{
content: "";
position: absolute;
top: 0;
left: 0;
height: 100%;
border-radius: 50px;
width: 100%;
background: linear-gradient(to right, rgba(0, 200, 0, .3), rgba(0, 100, 0, .8));
animation: purge 4s infinite ease-out
}
@keyframes purge{
0%{
opacity: 0;
width: 0%;
}
50%{
opacity: .5
}
100%{
opacity: 0;
width: 100%;
}
}
.cont .loader label{
font-size: 12px;
position: absolute;
right: -10px;
text-align: center;
top: -25px;
font-weight: 600;
transition: .3s;
}
.cont .loader:after{
content: "";
position: absolute;
top: -10px;
right: 0px;
height: 50%;
width: 2px;
background: rgba(0, 200, 0, .8);
}
.cont:hover .loader label{
transform: scale(1.5);
transition: .3s;
}
</style>
<script type="text/javascript">
window.addEventListener("load", loadProgress)
function loadProgress(){
// Get DOM element
const target = document.querySelector(".loader")
const counter = target.querySelector("span");
// Sample form data
const details = {
name: "Jefferson",
age: 12,
weight: 70,
level: 30,
relationship: "",
contact: "",
email: "",
friends: 459
}
function getProgress(board){
let maxLength = 100;
// Put them into array to get length of form
let lengthOfBoard = Object.values(board).length;
// Get possible mark of each field
let jumps = maxLength/lengthOfBoard;
let progress = 0;
for (let field in board){
// If field is filled add it's mark to progress
if (board[field]) {
progress += jumps
}
}
return progress
}
// Utilise value calculated from loader
function implimentLoad(){
// Simulate a delay
setTimeout(()=>{
let progress = Math.round(getProgress(details))
counter.innerText = `${progress}% `;
target.style.width = `${getProgress(details)}% `
}, 1000)
}
implimentLoad()
}
</script>
</body>
</html>