-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
141 lines (118 loc) · 3.39 KB
/
script.js
File metadata and controls
141 lines (118 loc) · 3.39 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const menuBtn = document.getElementById("menu-toggle");
const navLinks = document.querySelector(".navTopLinks");
const closeBtn = document.getElementById("close");
const links = document.querySelectorAll(".links li");
menuBtn.addEventListener("click", (e) => {
e.stopPropagation();
navLinks.classList.add("active");
document.body.style.overflow = "hidden";
});
closeBtn.addEventListener("click", () => {
navLinks.classList.remove("active");
document.body.style.overflow = "";
});
links.forEach((link) => {
link.addEventListener("click", () => {
navLinks.classList.remove("active");
document.body.style.overflow = "";
});
});
document.addEventListener("click", (e) => {
if (
navLinks.classList.contains("active") &&
!navLinks.contains(e.target) &&
!menuBtn.contains(e.target)
) {
navLinks.classList.remove("active");
document.body.style.overflow = "";
}
});
window.addEventListener("load", () => {
window.scrollTo(0, 0);
history.replaceState(null, "", window.location.pathname);
});
// Hero Section Image
const heroImages = document.getElementById("heroImgs");
const images = [
"images/HeroBg.jpg",
"images/HeroBg2.jpg",
"images/heroBg3.jpg",
];
images.forEach((src) => {
const img = new Image();
img.src = src; // forces browser to load & cache
});
let currentIndex = 0;
function changeBackround() {
heroImages.classList.remove("animate");
void heroImages.offsetWidth;
heroImages.style.background = `
linear-gradient(rgba(0,0,0,0.2), rgba(0,0,0,0.2)),
url("${images[currentIndex]}") center/cover no-repeat
`;
heroImages.classList.add("animate");
currentIndex = (currentIndex + 1) % images.length;
}
changeBackround();
setInterval(changeBackround, 4000);
// Sections scrolling in on view port
const allSections = document.querySelectorAll(".onViewPort");
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("show");
}
});
},
{
threshold: 0.3,
}
);
allSections.forEach((section) => observer.observe(section));
// Contact section
// Initialize EmailJS
emailjs.init("ItwcPnzp33zLoylGV");
const form = document.getElementById("formContainer");
const inputs = form.querySelectorAll("input, textarea");
form.addEventListener("submit", function (e) {
e.preventDefault();
let isValid = true;
// Custom validation
inputs.forEach((input) => {
const error = input.nextElementSibling; // <small class="error">
if (input.value.trim() === "") {
error.textContent = `${input.placeholder.replace("*", "")} is required`;
isValid = false;
} else {
error.textContent = "";
}
});
if (!isValid) return; // stop if invalid
// Send email via EmailJS
emailjs.sendForm("service_nf26lb2", "template_76nwt7e", form).then(
() => {
alert("Message sent successfully!");
form.reset();
},
(error) => {
console.error(error);
alert("Failed to send message 😢");
}
);
});
// FAQ section
const fqas = document.querySelectorAll(".fqa");
fqas.forEach((fqa) => {
const question = fqa.querySelector(".question");
question.addEventListener("click", () => {
// Close all other FAQs
fqas.forEach((other) => {
if (other !== fqa) {
other.classList.remove("active");
}
});
// Toggle the clicked FAQ
fqa.classList.toggle("active");
});
});