-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathscript.js
More file actions
54 lines (49 loc) · 1.82 KB
/
script.js
File metadata and controls
54 lines (49 loc) · 1.82 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
document.addEventListener("DOMContentLoaded", () => {
// 1. Intersection Observer for Scroll Animations
// This triggers the 'visible' class when elements scroll into view
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); // Only animate once
}
});
}, observerOptions);
const revealElements = document.querySelectorAll(".scroll-reveal");
revealElements.forEach((el) => observer.observe(el));
// 2. Smooth Scrolling for Anchor Links
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener("click", function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute("href"));
if (target) {
window.scrollTo({
top: target.offsetTop - 70, // Offset for fixed header
behavior: "smooth",
});
}
});
});
// 3. Simple Mobile Menu Toggle (Optional if you want to expand)
const hamburger = document.querySelector(".hamburger");
const navLinks = document.querySelector(".nav-links");
if (hamburger) {
hamburger.addEventListener("click", () => {
navLinks.style.display = navLinks.style.display === "flex" ? "none" : "flex";
if (navLinks.style.display === "flex") {
navLinks.style.flexDirection = "column";
navLinks.style.position = "absolute";
navLinks.style.top = "60px";
navLinks.style.right = "0";
navLinks.style.background = "#0f172a";
navLinks.style.width = "100%";
navLinks.style.padding = "20px";
navLinks.style.borderBottom = "1px solid #333";
}
});
}
});