-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
69 lines (60 loc) · 2.27 KB
/
Copy pathscript.js
File metadata and controls
69 lines (60 loc) · 2.27 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
const header = document.querySelector(".site-header");
const navToggle = document.querySelector(".nav-toggle");
const navLinks = document.querySelector(".nav-links");
const navItems = document.querySelectorAll(".nav-links a");
const sections = document.querySelectorAll("main section[id]");
const reveals = document.querySelectorAll(".reveal");
const contactForm = document.querySelector("#contactForm");
navToggle.addEventListener("click", () => {
const isOpen = navLinks.classList.toggle("open");
navToggle.setAttribute("aria-expanded", String(isOpen));
});
navItems.forEach((link) => {
link.addEventListener("click", () => {
navLinks.classList.remove("open");
navToggle.setAttribute("aria-expanded", "false");
});
});
const revealObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("visible");
revealObserver.unobserve(entry.target);
}
});
},
{ threshold: 0.16 }
);
reveals.forEach((element) => revealObserver.observe(element));
const sectionObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) return;
navItems.forEach((link) => {
link.classList.toggle("active", link.getAttribute("href") === `#${entry.target.id}`);
});
});
},
{
rootMargin: "-36% 0px -58% 0px",
threshold: 0.01
}
);
sections.forEach((section) => sectionObserver.observe(section));
window.addEventListener("scroll", () => {
header.classList.toggle("is-scrolled", window.scrollY > 12);
});
contactForm.addEventListener("submit", (event) => {
event.preventDefault();
const formData = new FormData(contactForm);
const name = formData.get("name").trim();
const email = formData.get("email").trim();
const subject = formData.get("subject").trim();
const message = formData.get("message").trim();
const status = contactForm.querySelector(".form-status");
const body = encodeURIComponent(`${message}\n\nFrom: ${name}\nEmail: ${email}`);
const mailSubject = encodeURIComponent(subject || "Portfolio contact");
window.location.href = `mailto:milanmanojp0@gmail.com?subject=${mailSubject}&body=${body}`;
status.textContent = "Opening your email client with the message payload.";
});