-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
73 lines (65 loc) · 2 KB
/
main.js
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
const toggle = document.getElementById('toggle');
const nav = document.getElementById('navBar');
toggle.addEventListener('click',() => {
nav.classList.toggle('active')
});
// roadmap
$(".step").click(function () {
$(this).addClass("active").prevAll().addClass("active");
$(this).nextAll().removeClass("active");
});
$(".step01").click(function () {
$("#line-progress").css("width", "3%");
$(".discovery").addClass("active").siblings().removeClass("active");
});
$(".step02").click(function () {
$("#line-progress").css("width", "25%");
$(".strategy").addClass("active").siblings().removeClass("active");
});
$(".step03").click(function () {
$("#line-progress").css("width", "50%");
$(".creative").addClass("active").siblings().removeClass("active");
});
$(".step04").click(function () {
$("#line-progress").css("width", "75%");
$(".production").addClass("active").siblings().removeClass("active");
});
$(".step05").click(function () {
$("#line-progress").css("width", "100%");
$(".analysis").addClass("active").siblings().removeClass("active");
});
const step = 100;
const counters = document.querySelectorAll(".counter");
async function getCount(name) {
switch (name) {
case "youtube":
// make api call
return 30000;
case "twitter":
return 12000;
case "instagram":
return 9000;
}
}
function loadValue(element, value) {
const increment = value / step;
function updateCounter() {
const c = +element.innerText;
if (c < value) {
element.innerText = `${Math.ceil(c + increment)}`;
setTimeout(updateCounter, 10);
} else {
element.innerText = value;
}
}
updateCounter();
}
function loadCounter() {
Array.from(counters || []).forEach(async (counter) => {
const name = counter.getAttribute("name");
counter.innerHTML = 0;
const count = await getCount(name);
loadValue(counter, count);
});
}
loadCounter();