-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (28 loc) · 1.03 KB
/
index.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
// navbar button
const toggleBtn = document.querySelector('.toggle_btn')
const toggleBtnIcon = document.querySelector('.toggle_btn i')
const dropDownMenu = document.querySelector('.dropdown_menu')
toggleBtn.onclick = function(){
dropDownMenu.classList.toggle('open')
}
// data counting
function animateValue(obj, start, end, duration) {
let startTimestamp = null;
const step = (timestamp) => {
if (!startTimestamp) startTimestamp = timestamp;
const progress = Math.min((timestamp - startTimestamp) / duration, 1);
obj.innerHTML = Math.floor(progress * (end - start) + start);
if (progress < 1) {
window.requestAnimationFrame(step);
}
};
window.requestAnimationFrame(step);
}
const obj1 = document.getElementById("value1");
animateValue(obj1, 0,1500, 9999);
const obj2 = document.getElementById("value2");
animateValue(obj2, 0, 40, 9999);
const obj3 = document.getElementById("value3");
animateValue(obj3, 0, 4, 9999);
const obj4 = document.getElementById("value4");
animateValue(obj4, 0, 10, 9999);