-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
173 lines (156 loc) · 5.48 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Hamburger menu animation
const hamburgerMenu = document.getElementById("hamburger-menu");
const hamburgerLines = document.querySelectorAll(".hamburger-lines");
const modalBg = document.querySelector(".modal-bg");
const modal = document.querySelector(".modal");
hamburgerMenu.addEventListener('click', function () {
hamburgerMenu.classList.toggle("active");
if (hamburgerMenu.className.includes("active")) {
hamburgerLines.forEach(line => line.classList.add("active-line"));
hamburgerLines.forEach(line => line.classList.remove("inactive-line"));
// Fade-In animation
modalBg.classList.remove("fade-out");
modal.classList.remove("fade-out");
modalBg.classList.add("fade-in");
modal.classList.add("fade-in");
} else {
hamburgerLines.forEach(line => line.classList.add("inactive-line"));
hamburgerLines.forEach(line => line.classList.remove("active-line"));
// Fade-Out animation
modalBg.classList.remove("fade-in");
modal.classList.remove("fade-in");
modalBg.classList.add("fade-out");
modal.classList.add("fade-out");
}
});
function changeNavbarActive(section) {
document.querySelector(".hero-nav-link.active").classList.remove("active");
document.querySelector(".hero-modal-link.active").classList.remove("active");
document.getElementById(`${section}-nav-link`).classList.add("active");
document.getElementById(`${section}-modal-link`).classList.add("active");
}
function scrollToSection(section) {
const element = document.getElementById(section);
element.scrollIntoView({ behavior: "smooth" });
changeNavbarActive(section);
}
const skills = {
HTML: {
percent: "90%",
icon: "fa fa-html5",
color: "rgb(255 67 34)"
},
CSS: {
percent: "80%",
icon: "fa fa-css3",
color: "rgb(0, 132, 255)"
},
JavaScript: {
percent: "90%",
icon: "fab fa-js",
color: "rgb(255, 217, 0)"
},
ReactJs: {
percent: "85%",
icon: "fab fa-react",
color: "#61dafb"
},
NodeJs: {
percent: "60%",
icon: "fab fa-node-js",
color: "#6DA15D"
},
Git: {
percent: "45%",
icon: "fab fa-git-alt",
color: "red"
},
Database: {
percent: "85%",
icon: "fas fa-database",
color: "darkgray"
}
}
function createSkills() {
const skillsContainer = document.getElementById("skills-container");
Object.keys(skills).map(skill => {
const { percent, icon, color } = skills[skill];
const skillsDiv = document.createElement("DIV");
skillsDiv.className = `skills-div skills-${skill.toLowerCase()}`;
skillsDiv.innerHTML = `
<div>
<i class="${icon}" style="color: ${color}"></i><span>${skill}</span>
</div>
<div class="progress-bar-container">
<div skill="${skill}" class="progress-bar" style="width: ${percent}; background: ${color}"></div>
<span class="progress-bar-percent">${percent}</span>
</div>
`
skillsContainer.appendChild(skillsDiv);
})
}
createSkills();
function isScrolledIntoView(elem) {
const bounding = elem.getBoundingClientRect();
const y = Math.floor(bounding.y);
const halfHeight = Math.floor(bounding.height / 2);
return (y - halfHeight) <= y <= (y + halfHeight);
}
window.onscroll = function () {
const home = document.getElementById("home");
const hobbies = document.getElementById("hobbies");
const skills = document.getElementById("skills");
const goToTop = document.getElementById("go-to-top");
const photoGroup = document.getElementById("hero-photo-group");
const aboutMe = document.getElementById("hero-about-me");
let insideHero = false;
if (isScrolledIntoView(home)) {
changeNavbarActive("home");
insideHero = true;
}
else if (isScrolledIntoView(hobbies)) {
changeNavbarActive("hobbies");
goToTop.style.display = "flex";
}
else if (isScrolledIntoView(skills)) {
changeNavbarActive("skills");
}
goToTop.classList.toggle("fade-out", insideHero);
goToTop.classList.toggle("fade-in", !insideHero);
photoGroup.classList.toggle("show", insideHero);
aboutMe.classList.toggle("show", insideHero);
}
window.setTimeout(() => {
document.getElementById("hero-photo-group").classList.add("show");
document.getElementById("hero-about-me").classList.add("show");
}, 100)
// Hobbies Section Animations
const hobbiesObserver = new IntersectionObserver(entries => {
entries.forEach(entry => {
entry.target.classList.toggle("show", entry.isIntersecting);
})
}, {
threshold: 0.3
});
const hobbiesWrappers = document.querySelectorAll(".hobbies-wrapper");
hobbiesWrappers.forEach(hobbiesWrapper => {
hobbiesObserver.observe(hobbiesWrapper);
})
// Skills Section Animations
const skillsObserver = new IntersectionObserver(entries => {
entries.forEach(entry => {
const progressBar = entry.target;
if (entry.isIntersecting) {
progressBar.style.width = skills[progressBar.getAttribute("skill")].percent;
} else {
progressBar.style.width = 0;
}
progressBar.classList.toggle("show", entry.isIntersecting);
})
}, {
threshold: 0.5
})
const progressBars = document.querySelectorAll(".progress-bar")
progressBars.forEach(progressBar => {
skillsObserver.observe(progressBar);
})