-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
43 lines (38 loc) · 1.23 KB
/
scripts.js
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
document.addEventListener("DOMContentLoaded", () => {
const burger = document.getElementById("burger");
const navLinks = document.getElementById("nav-links");
const links = navLinks.querySelectorAll("a");
// Toggle navbar and change burger icon to cross
burger.addEventListener("click", () => {
navLinks.classList.toggle("nav-active");
burger.classList.toggle("cross");
});
// Close navbar when a link is clicked
document.querySelectorAll(".nav-links a").forEach((link) => {
link.addEventListener("click", () => {
navLinks.classList.remove("nav-active");
burger.classList.remove("cross");
});
});
// Close the nav when a link is clicked
links.forEach((link) => {
link.addEventListener("click", () => {
navLinks.classList.remove("nav-active");
});
});
// Intersection Observer for elements with 'animated' class
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("visible");
}
});
},
{ threshold: 0.1 }
);
// Observe each animated element
document.querySelectorAll(".animated").forEach((element) => {
observer.observe(element);
});
});