-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
80 lines (64 loc) · 2.12 KB
/
Copy pathscript.js
File metadata and controls
80 lines (64 loc) · 2.12 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
// Mobile navigation
const menuToggle = document.querySelector("#menu-toggle");
const navLinks = document.querySelector("#nav-links");
const siteHeader = document.querySelector(".site-header");
menuToggle.addEventListener("click", () => {
navLinks.classList.toggle("show");
});
navLinks.addEventListener("click", (event) => {
if (event.target.tagName === "A") {
navLinks.classList.remove("show");
}
});
function updateHeaderState() {
if (window.scrollY > 20) {
siteHeader.classList.add("scrolled");
} else {
siteHeader.classList.remove("scrolled");
}
}
// Highlight the active section in the navigation
const sections = document.querySelectorAll("section");
const navItems = document.querySelectorAll(".nav-links a");
window.addEventListener("scroll", () => {
let currentSection = "";
sections.forEach((section) => {
const sectionTop = section.offsetTop - 120;
if (window.scrollY >= sectionTop) {
currentSection = section.getAttribute("id");
}
});
navItems.forEach((link) => {
link.classList.remove("active");
if (link.getAttribute("href") === `#${currentSection}`) {
link.classList.add("active");
}
});
});
window.addEventListener("scroll", updateHeaderState);
updateHeaderState();
// Contact form message
const contactForm = document.querySelector(".contact-form");
const formStatus = document.querySelector("#form-status");
contactForm.addEventListener("submit", (event) => {
event.preventDefault();
formStatus.textContent = "Thanks! Your message has been received.";
contactForm.reset();
});
// Back-to-top button
const backToTopButton = document.querySelector("#back-to-top");
window.addEventListener("scroll", () => {
if (window.scrollY > 500) {
backToTopButton.classList.add("show");
} else {
backToTopButton.classList.remove("show");
}
});
backToTopButton.addEventListener("click", () => {
window.scrollTo({
top: 0,
behavior: "smooth"
});
});
// Current year in the footer
document.querySelector("#year").textContent = new Date().getFullYear();