-
Notifications
You must be signed in to change notification settings - Fork 0
/
increment_counter.html
68 lines (51 loc) · 2.18 KB
/
increment_counter.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
<!DOCTYPE html>
<html>
<head>
<title>Increment Counter</title>
<!-- <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> -->
</head>
<body>
<h1>Hello</h1>
<div class='counter-container'>
<div class='Counter' data-target="4000"></div>
<span>Orders Completed</span>
</div>
<div class='counter-container'>
<div class = 'Counter' data-target="15000"></div>
<span>Happy Clients</span>
</div>
<div class='counter-container'></div>
<div class = 'Counter' id='project' data-target="1000"></div>
<span>Ongoing Projects</span>
</div>
<script>
const counters = document.querySelectorAll('.Counter');
console.log(counters);
counters.forEach((count) => {
// console.log('Hello');
count.innerHTML = 0;
const updateCounter = () =>{
const startCount = Number(count.innerHTML);
const targetCount = Number(count.getAttribute('data-target'));
// console.log(typeof(targetCount));
let incr = targetCount/100;
if(startCount<targetCount){
count.innerHTML = Math.round(startCount + incr);
setTimeout(updateCounter, 10);
}
else{
count.innerHTML = targetCount;
// let temp = document.getElementById('project');
// temp.style.color = '#f8b627';
let x = document.querySelectorAll('.Counter');
for( var i =0; i<x.length; i++){
x[i].style.backgroundColor='blue';
}
}
}
updateCounter();
});
</script>
</body>
</html>