-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
373 lines (305 loc) · 11.5 KB
/
Copy pathscript.js
File metadata and controls
373 lines (305 loc) · 11.5 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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
const navLinks = document.querySelectorAll("header nav a");
const nav2Containers = document.querySelectorAll("footer .nav-2-container");
const sections = document.querySelectorAll("section");
const logoLink = document.querySelector(".logo");
const menuIcon = document.querySelector("#menu-icon");
const navbar = document.querySelector("header nav");
let currentActiveIndex = 0; // Tracks the index of the currently active section
// Function to reset active states and trigger the bars animation
const resetActiveStateWithBars = () => {
const barsBox = document.querySelector(".bars-box");
const header = document.querySelector("header");
if (!barsBox || !header) {
console.error("barsBox or header is missing in the DOM!");
return;
}
// First, hide the header and sections (before bar animation)
header.classList.remove("active");
sections.forEach((section) => section.classList.remove("active"));
// Trigger hide bars animation
barsBox.classList.remove("active");
// Reapply animations to ensure they are triggered
const bars = barsBox.querySelectorAll(".bar");
bars.forEach((bar) => {
bar.style.animation = "none"; // Remove animation temporarily
void bar.offsetHeight; // Force reflow/repaint
bar.style.animation = ""; // Reapply animation
});
// Set a timeout to delay the show bars animation to give time for hide bars animation
setTimeout(() => {
// Reset all active states after the animation completes
navLinks.forEach((link) => link.classList.remove("active"));
nav2Containers.forEach((container) => {
container.querySelector("a").classList.remove("active");
container.querySelector("i").classList.remove("active");
});
// Trigger show bars animation after delay
barsBox.classList.add("active");
header.classList.add("active"); // Re-add the 'active' class to the header
}, 1100); // Delay the show bars animation to allow hide bars to finish (matches hide bars duration)
};
// Function to set active state for a specific index
const setActiveState = (index) => {
// Update active class for nav link
navLinks[index].classList.add("active");
// Update active class for nav-2 link and its icon
const nav2Link = nav2Containers[index].querySelector("a");
const nav2Icon = nav2Containers[index].querySelector("i");
nav2Link.classList.add("active");
nav2Icon.classList.add("active");
// Activate the corresponding section
sections[index].classList.add("active");
// Update the current active index
currentActiveIndex = index;
};
// Add click event listeners for `nav` and `nav-2` links
const addClickListeners = (links, isNav2 = false) => {
links.forEach((link, idx) => {
link.addEventListener("click", (event) => {
event.preventDefault(); // Prevent default anchor behavior
// Skip if the clicked link corresponds to the current active section
if (idx === currentActiveIndex) {
return;
}
resetActiveStateWithBars();
setTimeout(() => {
setActiveState(idx);
// Hide the navbar after section load
navbar.classList.remove("active"); // Hide the navbar after clicking a link
}, 1100); // Set active state after animation (matches animation duration)
});
});
};
// Attach listeners to both nav links and nav-2 links
addClickListeners(navLinks);
addClickListeners(
Array.from(nav2Containers).map((container) => container.querySelector("a"))
);
// Add click event listeners for `nav-2` icons
nav2Containers.forEach((container, idx) => {
const nav2Icon = container.querySelector("i");
nav2Icon.addEventListener("click", (event) => {
event.preventDefault(); // Prevent default behavior
// Skip if the clicked icon corresponds to the current active section
if (idx === currentActiveIndex) {
return;
}
resetActiveStateWithBars();
setTimeout(() => {
setActiveState(idx);
navbar.classList.remove("active"); // Hide the navbar after clicking an icon
}, 1100); // Set active state after animation (matches animation duration)
});
});
// Toggle menu icon and navbar visibility
menuIcon.addEventListener("click", () => {
// Only toggle the menu when the menu icon itself is clicked, not when a nav link is clicked
navbar.classList.toggle("active");
});
// Resume Buttons and Portfolio Carousel functionality remain untouched.
// Add a click event listener to the logo link to reset to the first section
logoLink.addEventListener("click", () => {
if (!navLinks[0].classList.contains("active")) {
activePage();
navLinks[0].classList.add("active");
setTimeout(() => {
sections[0].classList.add("active");
}, 1100);
}
});
// Function to handle the transition between pages
const transitionPage = (idx) => {
const barsBox = document.querySelector(".bars-box");
const header = document.querySelector("header");
sections.forEach((section) => {
section.classList.remove("active");
});
// Wait for the hide-bars animation to finish before updating the page
setTimeout(() => {
barsBox.classList.add("active");
// Update navigation links to reflect the active section
navLinks.forEach((link) => link.classList.remove("active"));
navLinks[idx].classList.add("active");
}, 1100);
};
// Add click event listeners to navigation links for transitioning pages
navLinks.forEach((link, idx) => {
link.addEventListener("click", (event) => {
event.preventDefault();
if (!link.classList.contains("active")) {
transitionPage(idx);
}
});
});
// Resume Buttons Functionality
const resumeBtns = document.querySelectorAll(".resume-btn");
resumeBtns.forEach((btn, idx) => {
btn.addEventListener("click", () => {
const resumeDetails = document.querySelectorAll(".resume-detail");
// Remove the 'active' class from all buttons
resumeBtns.forEach((btn) => {
btn.classList.remove("active");
});
btn.classList.add("active");
resumeDetails.forEach((detail) => {
detail.classList.remove("active");
});
// Add the 'active' class to the corresponding resume detail
resumeDetails[idx].classList.add("active");
});
});
// Portfolio Carousel Functionality
const arrowRight = document.querySelector(
".portfolio-box .navigation .arrow-right"
);
const arrowLeft = document.querySelector(
".portfolio-box .navigation .arrow-left"
);
// Initialize index for portfolio navigation
let index = 0;
// Function to update the portfolio carousel and details
const activePortfolio = () => {
const imgSlide = document.querySelector(".portfolio-carousel .img-slide");
const portfolioDetails = document.querySelectorAll(".portfolio-detail");
imgSlide.style.transform = `translateX(calc(${index * -100}% - ${
index * 2
}rem))`;
portfolioDetails.forEach((detail) => {
detail.classList.remove("active");
});
portfolioDetails[index].classList.add("active");
};
// Add click event listener to the right arrow
arrowRight.addEventListener("click", () => {
if (index < 4) {
index++;
arrowLeft.classList.remove("disabled");
} else {
index = 5;
arrowRight.classList.add("disabled");
}
activePortfolio();
});
// Add click event listener to the left arrow
arrowLeft.addEventListener("click", () => {
if (index > 1) {
index--;
arrowRight.classList.remove("disabled");
} else {
index = 0;
arrowLeft.classList.add("disabled");
}
activePortfolio();
});
// Existing Variables and Elements
const sliderContainer = document.querySelector(".slider-container");
const sliderItems = document.querySelectorAll(".slider-item");
const prevButton = document.querySelector(".slider-prev");
const nextButton = document.querySelector(".slider-next");
const paginationContainer = document.querySelector(".slider-pagination");
const popup = document.querySelector(".blog-popup");
const popupContent = document.querySelector(".blog-text");
const closePopup = document.querySelector(".close-popup");
const itemsPerSlide = 2; // Number of images visible at once
let currentIndex = 0;
// Function to update the slider position and active class
const updateSliderPosition = () => {
const totalSlides = sliderItems.length;
// Calculate the offset to center the active image
const offset = (itemsPerSlide - 1) / 2;
// Move the slider
const translateValue =
Math.max(0, currentIndex - offset) * (100 / itemsPerSlide);
sliderContainer.style.transform = `translateX(-${translateValue}%)`;
// Update active class
sliderItems.forEach((item, index) => {
item.classList.toggle("active", index === currentIndex);
});
// Disable buttons when at the beginning or end
prevButton.disabled = currentIndex === 0;
nextButton.disabled = currentIndex === totalSlides - 1;
// Update pagination active dot
updatePaginationDots();
};
// Function to update pagination dots
const updatePaginationDots = () => {
const dots = paginationContainer.querySelectorAll(".pagination-dot");
dots.forEach((dot, index) => {
dot.classList.toggle("active", index === currentIndex);
});
};
// Function to create pagination dots
const createPagination = () => {
const totalSlides = sliderItems.length;
for (let i = 0; i < totalSlides; i++) {
const dot = document.createElement("button");
dot.classList.add("pagination-dot");
if (i === currentIndex) dot.classList.add("active");
// Add click event to navigate to the corresponding slide
dot.addEventListener("click", () => {
currentIndex = i;
updateSliderPosition();
});
paginationContainer.appendChild(dot);
}
};
// Event listeners for navigation buttons
prevButton.addEventListener("click", () => {
if (currentIndex > 0) {
currentIndex--;
updateSliderPosition();
}
});
nextButton.addEventListener("click", () => {
if (currentIndex < sliderItems.length - 1) {
currentIndex++;
updateSliderPosition();
}
});
// Initialize the slider
window.addEventListener("load", () => {
updateSliderPosition();
createPagination();
});
// Add click event for "Read More" buttons
// sliderItems.forEach((item) => {
// const readMoreButton = item.querySelector(".read-more-btn");
// readMoreButton.addEventListener("click", () => {
// const blogContent = item.getAttribute("data-blog");
// popupContent.textContent = blogContent;
// popup.classList.add("show");
// });
// });
// Close popup event
// closePopup.addEventListener("click", () => {
// popup.classList.remove("show");
// });
// Close popup when clicking outside the popup content
// popup.addEventListener("click", (event) => {
// if (event.target === popup) {
// popup.classList.remove("show");
// }
// });
// Fetch all the Read More buttons
// const readMoreButtons = document.querySelectorAll(".read-more-btn");
// Add click listeners to each button
// readMoreButtons.forEach((button) => {
// button.addEventListener("click", (e) => {
// const sliderItem = e.target.closest(".slider-item");
// const blogContent = sliderItem.querySelector(
// ".hidden-blog-content"
// ).innerHTML;
// const popup = document.querySelector(".blog-popup");
// const popupContent = popup.querySelector(".blog-text");
// popupContent.innerHTML = blogContent;
// popup.style.display = "block";
// });
// });
// Close the popup when the close button is clicked
// const closePopupButton = document.querySelector(".close-popup");
// closePopupButton.addEventListener("click", () => {
// const popup = document.querySelector(".blog-popup");
// popup.style.display = "none";
// const popupContent = popup.querySelector(".blog-text");
// popupContent.innerHTML = "";
// });