-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
77 lines (59 loc) · 2.1 KB
/
Copy pathmain.js
File metadata and controls
77 lines (59 loc) · 2.1 KB
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
//skills bars animation\\
const skillsSection = document.getElementById('skills-item');
const progressBars = document.querySelectorAll('.progress-bar');
function showProgress() {
progressBars.forEach(progressBars => {
const value = progressBars.dataset.progress;
progressBars.style.opacity = 1;
progressBars.style.width = `${value}%`;
});
}
function hideProgress() {
progressBars.forEach(h3 => {
h3.style.opacity = 0;
h3.style.width = 0;
});
}
window.addEventListener('scroll', () => {
const sectionPos = skillsSection.getBoundingClientRect().top;
const screenPos = window.innerHeight / 2;
if (sectionPos < screenPos) {
showProgress();
} else {
hideProgress();
}
});
//counter animation\\
function animate(obj, initVal, lastVal, duration) {
let startTime = null;
//get the current timestamp and assign it to the currentTime variable
let currentTime = Date.now();
//pass the current timestamp to the step function
const step = (currentTime) => {
//if the start time is null, assign the current time to startTime
if (!startTime) {
startTime = currentTime;
}
//calculate the value to be used in calculating the number to be displayed
const progress = Math.min((currentTime - startTime) / duration, 1);
//calculate what to be displayed using the value gotten above
obj.innerHTML = Math.floor(progress * (lastVal - initVal) + initVal);
//checking to make sure the counter does not exceed the last value (lastVal)
if (progress < 1) {
window.requestAnimationFrame(step);
} else {
window.cancelAnimationFrame(window.requestAnimationFrame(step));
}
};
//start animating
window.requestAnimationFrame(step);
}
let text1 = document.getElementById('Cproject');
let text2 = document.getElementById('Hclients');
let text3 = document.getElementById('Previews');
const load = () => {
animate(text1, 0, 65, 5000);
animate(text2, 0, 27, 5000);
animate(text3, 100, 75, 5000);
}
//text effect