-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
64 lines (54 loc) · 1.68 KB
/
Copy pathscript.js
File metadata and controls
64 lines (54 loc) · 1.68 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
const menuIcon = document.querySelector(".mobile");
const navMenu = document.querySelector("#nav-menu");
menuIcon.addEventListener("click", () => {
navMenu.classList.toggle("show-nav");
menuIcon.classList.toggle("fa-bars");
menuIcon.classList.toggle("fa-x");
});
const navLinks = document.querySelectorAll("#nav-menu a");
navLinks.forEach((link) => {
link.addEventListener("click", () => {
navMenu.classList.remove("show-nav");
menuIcon.classList.add("fa-bars");
menuIcon.classList.remove("fa-x");
});
});
// Scroll to Top Button Logic
const scrollToTopBtn = document.getElementById("scrollToTopBtn");
window.addEventListener("scroll", () => {
if (window.scrollY > 300) {
scrollToTopBtn.classList.add("show");
} else {
scrollToTopBtn.classList.remove("show");
}
});
scrollToTopBtn.addEventListener("click", () => {
window.scrollTo({ top: 0, behavior: "smooth" });
});
// contact form submission
const form = document.getElementById("contactForm");
const status = document.getElementById("formStatus");
form.addEventListener("submit", async (e) => {
e.preventDefault();
status.textContent = "Sending message...";
const data = {
name: form.name.value,
email: form.email.value,
subject: form.subject.value,
message: form.message.value,
};
try {
const res = await fetch("/api/contact", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
if (res.ok) {
window.location.href = "/thank-you.html";
} else {
status.textContent = "Something went wrong. Try again.";
}
} catch (err) {
status.textContent = "Network error. Please try again.";
}
});