-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript2.js
More file actions
42 lines (36 loc) · 1.11 KB
/
script2.js
File metadata and controls
42 lines (36 loc) · 1.11 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
const hamburger = document.querySelector(".hamburger");
const navLinks = document.querySelector(".nav-links");
hamburger.addEventListener("click", function () {
hamburger.classList.toggle("active");
navLinks.classList.toggle("active");
});
document.querySelectorAll(".nav-link").forEach((link) => {
link.addEventListener("click", () => {
hamburger.classList.remove("active");
navLinks.classList.remove("active");
});
});
const fadeElements = document.querySelectorAll(".fade-in");
const fadeInObserver = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("visible");
}
});
},
{ threshold: 0.1 }
);
// THIS IS THE CRITICAL PART THAT WAS LIKELY MISSING
// It makes all the content at the top of the page visible on load.
setTimeout(() => {
fadeElements.forEach((el) => {
const rect = el.getBoundingClientRect();
if (rect.top < window.innerHeight && rect.bottom >= 0) {
el.classList.add("visible");
}
});
}, 100);
fadeElements.forEach((element) => {
fadeInObserver.observe(element);
});