-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
105 lines (89 loc) · 3.01 KB
/
script.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* Progress bar Effect */
const navbar = document.querySelector(".navbar");
const navbarOffsetTop = navbar.offsetTop;
const sections = document.querySelectorAll("section");
const navbarLinks = document.querySelectorAll(".navbar-link");
const progress = document.querySelector(".progress-bars-wrapper");
const progressBarPercents = [97, 90,50, 60];
window.addEventListener("scroll", () => {
mainFn();
});
const mainFn = () => {
if (window.pageYOffset >= navbarOffsetTop) {
navbar.classList.add("sticky");
} else {
navbar.classList.remove("sticky");
}
sections.forEach((section, i) => {
if (window.pageYOffset >= section.offsetTop - 10) {
navbarLinks.forEach((navbarLink) => {
navbarLink.classList.remove("change");
});
navbarLinks[i].classList.add("change");
}
});
if (window.pageYOffset + window.innerHeight >= progress.offsetTop) {
document.querySelectorAll(".progress-percent").forEach((el, i) => {
el.style.width = `${progressBarPercents[i]}%`;
el.previousElementSibling.firstElementChild.textContent =
progressBarPercents[i];
});
}
};
mainFn();
window.addEventListener("resize", () => {
window.location.reload();
});
/* Typing and Deleting Effect */
// List of sentences
var _CONTENT = [
"SOFTWARE ENGINEER",
"WEB DEVELOPER",
"OPEN SOURCE CONTRIBUTOR",
"CODER"
];
var _PART = 0; // Current sentence being processed
var _PART_INDEX = 0; // Character number of the current sentence being processed
var _INTERVAL_VAL; // Holds the handle returned from setInterval
var _ELEMENT = document.querySelector("#text-name"); // Element that holds the text
var _CURSOR = document.querySelector("#cursor"); // Cursor element
// Implements typing effect
function Type() {
// Get substring with 1 characater added
var text = _CONTENT[_PART].substring(0, _PART_INDEX + 1);
_ELEMENT.innerHTML = text;
_PART_INDEX++;
// If full sentence has been displayed then start to delete the sentence after some time
if(text === _CONTENT[_PART]) {
// Hide the cursor
_CURSOR.style.display = 'none';
clearInterval(_INTERVAL_VAL);
setTimeout(function() {
_INTERVAL_VAL = setInterval(Delete, 50);
}, 1000);
}
}
// Implements deleting effect
function Delete() {
// Get substring with 1 characater deleted
var text = _CONTENT[_PART].substring(0, _PART_INDEX - 1);
_ELEMENT.innerHTML = text;
_PART_INDEX--;
// If sentence has been deleted then start to display the next sentence
if(text === '') {
clearInterval(_INTERVAL_VAL);
// If current sentence was last then display the first one, else move to the next
if(_PART == (_CONTENT.length - 1))
_PART = 0;
else
_PART++;
_PART_INDEX = 0;
// Start to display the next sentence after some time
setTimeout(function() {
_CURSOR.style.display = 'inline-block';
_INTERVAL_VAL = setInterval(Type, 100);
}, 200);
}
}
// Start the typing effect on load
_INTERVAL_VAL = setInterval(Type, 100);