-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
41 lines (34 loc) · 1006 Bytes
/
script.js
File metadata and controls
41 lines (34 loc) · 1006 Bytes
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
document.addEventListener("DOMContentLoaded", () => {
var navbar = document.getElementById("navbar")
function updateNavbar() {
if (window.scrollY > 50) {
navbar.classList.add("scrolled")
navbar.classList.remove("transparent")
} else {
navbar.classList.remove("scrolled")
navbar.classList.add("transparent")
}
}
// Initial check
updateNavbar()
// Update on scroll
window.addEventListener("scroll", updateNavbar)
// Intersection Observer for animations
const animatedElements = document.querySelectorAll(".fade-in")
const observerOptions = {
root: null,
rootMargin: "0px",
threshold: 0.1,
}
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("animate")
observer.unobserve(entry.target)
}
})
}, observerOptions)
animatedElements.forEach((element) => {
observer.observe(element)
})
})