-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresume.js
79 lines (58 loc) · 1.9 KB
/
resume.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
73
74
75
76
77
78
79
function main(event){
event.preventDefault();
var targetSectionId=this.textContent.trim().toLowerCase();
var targetSection=document.getElementById(targetSectionId);
var scrollInterval=setInterval(function (){
var targetCoordinates= targetSection.getBoundingClientRect();
if(targetCoordinates.top<=0)
{
clearInterval(scrollInterval);
return;
}
scrollBy(0,60);
},10);
}
var v=document.querySelectorAll(".nav-menu a");
for(let i=0;i<v.length;i++)
{
v[i].addEventListener("click",main);
}
// Bar filling
var progressBars = document.querySelectorAll(".skill-bar > div");
function initialiseBar(bar) {
bar.setAttribute("data-visited", false);
bar.style.width = 0 ;
}
for (var bar of progressBars) {
initialiseBar(bar);
}
function fillBar(bar) {
var currentWidth = 0;
var targetWidth = bar.getAttribute("data-bar-width");
var interval = setInterval(function () {
if (currentWidth >= targetWidth) {
clearInterval(interval);
return;
}
currentWidth++;
bar.style.width = currentWidth+"%";
console.log(bar.style.width);
}, 5);
}
// This function uses a for loop for individual progress bars.
function checkScroll() {
for (let bar of progressBars) {
var barCoordinates = bar.getBoundingClientRect();
if ((bar.getAttribute("data-visited") == "false") &&
(barCoordinates.top <= (window.innerHeight - barCoordinates.height))) {
bar.setAttribute("data-visited", true);
fillBar(bar);
} else if (barCoordinates.top > window.innerHeight) {
bar.setAttribute("data-visited", false);
initialiseBar(bar);
}
}
}
window.addEventListener("scroll", checkScroll);
// This event fills the progress bars if they are displayed on the screen when the page is loaded.
//window.addEventListener("load", checkScroll);