-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
114 lines (100 loc) · 3.23 KB
/
script.js
File metadata and controls
114 lines (100 loc) · 3.23 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
// Smooth scroll for navigation links
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener("click", function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute("href"));
if (target) {
const offset = 100;
const targetPosition = target.offsetTop - offset;
window.scrollTo({
top: targetPosition,
behavior: "smooth",
});
}
});
});
// Update active nav tab
const navTabs = document.querySelectorAll(".nav-tab");
const sections = document.querySelectorAll("section[id]");
function updateActiveNav() {
const scrollY = window.pageYOffset + 150;
sections.forEach((section) => {
const sectionHeight = section.offsetHeight;
const sectionTop = section.offsetTop;
const sectionId = section.getAttribute("id");
if (scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
navTabs.forEach((tab) => {
tab.classList.remove("active");
if (tab.getAttribute("href") === `#${sectionId}`) {
tab.classList.add("active");
}
});
}
});
}
window.addEventListener("scroll", updateActiveNav);
updateActiveNav();
// Intersection Observer for slide-up animations
const observerOptions = {
threshold: 0.1,
rootMargin: "0px 0px -50px 0px",
};
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("visible");
observer.unobserve(entry.target);
}
});
}, observerOptions);
document.querySelectorAll(".slide-up").forEach((el) => {
observer.observe(el);
});
// Animate progress bars on scroll
const progressBars = document.querySelectorAll(".progress-bar");
const progressObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
const width = entry.target.style.width;
entry.target.style.width = "0%";
setTimeout(() => {
entry.target.style.width = width;
}, 100);
progressObserver.unobserve(entry.target);
}
});
},
{ threshold: 0.5 }
);
progressBars.forEach((bar) => {
progressObserver.observe(bar);
});
// Mobile Menu Toggle
const mobileMenuButton = document.getElementById("mobile-menu-button");
const mobileMenu = document.getElementById("mobile-menu");
const menuIcon = document.getElementById("menu-icon");
const closeIcon = document.getElementById("close-icon");
if (mobileMenuButton && mobileMenu && menuIcon && closeIcon) {
mobileMenuButton.addEventListener("click", function () {
const isHidden = mobileMenu.classList.contains("hidden");
if (isHidden) {
mobileMenu.classList.remove("hidden");
menuIcon.classList.add("hidden");
closeIcon.classList.remove("hidden");
} else {
mobileMenu.classList.add("hidden");
menuIcon.classList.remove("hidden");
closeIcon.classList.add("hidden");
}
});
// Close menu when clicking on a link
const mobileMenuLinks = mobileMenu.querySelectorAll("a");
mobileMenuLinks.forEach((link) => {
link.addEventListener("click", function () {
mobileMenu.classList.add("hidden");
menuIcon.classList.remove("hidden");
closeIcon.classList.add("hidden");
});
});
}