-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
150 lines (126 loc) · 3.96 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
/* Credit and Thanks:
Matrix - Particles.js;
SliderJS - Ettrics;
Design - Sara Mazal Web;
Fonts - Google Fonts
*/
document.addEventListener("DOMContentLoaded", () => {
// Initialize Particles.js
const particles = Particles.init({
selector: ".background",
color: ["#9b59b6", "#ffff00", "#000000"],
connectParticles: true,
responsive: [
{
breakpoint: 768,
options: {
color: ["#faebd7", "#9b59b6", "#ffff00"],
maxParticles: 43,
connectParticles: false,
},
},
],
});
// Navigation Behavior
class Navigation {
constructor() {
this.currentTab = null;
this.lastScroll = 0;
this.init();
}
init() {
const navTabs = document.querySelectorAll(".nav-tab");
const navContainer = document.querySelector(".nav-container");
navTabs.forEach((tab) => {
tab.addEventListener("click", (e) => this.scrollToSection(e, tab));
});
window.addEventListener("scroll", () => this.handleScroll(navContainer));
window.addEventListener("resize", () => this.updateSlider());
}
scrollToSection(event, tab) {
event.preventDefault();
const targetId = tab.getAttribute("href");
const targetElement = document.querySelector(targetId);
if (targetElement) {
const offsetTop =
targetElement.offsetTop - document.querySelector(".nav-container").offsetHeight;
window.scrollTo({
top: offsetTop,
behavior: "smooth",
});
}
}
handleScroll(navContainer) {
const headerHeight = 75;
// Sticky Nav Behavior
if (window.scrollY > headerHeight) {
navContainer.classList.add("nav-container--scrolled");
} else {
navContainer.classList.remove("nav-container--scrolled");
}
// Tab Highlight Logic
this.highlightCurrentTab();
}
highlightCurrentTab() {
const navTabs = document.querySelectorAll(".nav-tab");
let currentTab = null;
navTabs.forEach((tab) => {
const sectionId = tab.getAttribute("href");
const section = document.querySelector(sectionId);
if (section) {
const sectionTop = section.offsetTop - 80; // Offset to account for sticky nav
const sectionBottom = sectionTop + section.offsetHeight;
if (window.scrollY >= sectionTop && window.scrollY < sectionBottom) {
currentTab = tab;
}
}
});
// Update Slider
if (currentTab) {
this.updateSlider(currentTab);
}
}
updateSlider(activeTab) {
const slider = document.querySelector(".nav-tab-slider");
if (activeTab) {
const tabRect = activeTab.getBoundingClientRect();
slider.style.width = `${tabRect.width}px`;
slider.style.left = `${tabRect.left}px`;
}
}
}
// Fade-In Effect
const fadeInElements = document.querySelectorAll(".fade-in");
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("visible");
}
});
},
{ threshold: 0.1 }
);
fadeInElements.forEach((element) => observer.observe(element));
// Modal Functionality
const modal = document.getElementById("modal");
const openModalButton = document.getElementById("openModal");
const closeModalButton = document.getElementById("closeModal");
if (modal && openModalButton && closeModalButton) {
openModalButton.addEventListener("click", (e) => {
e.preventDefault();
modal.classList.remove("hidden");
setTimeout(() => {
modal.classList.add("show");
}, 10); // Small delay for animation
});
closeModalButton.addEventListener("click", () => {
modal.classList.remove("show");
setTimeout(() => {
modal.classList.add("hidden");
}, 500); // Wait for animation to complete
});
}
// Initialize Navigation
new Navigation();
});