-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (38 loc) · 1.36 KB
/
Copy pathscript.js
File metadata and controls
46 lines (38 loc) · 1.36 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
document.addEventListener('DOMContentLoaded', () => {
const menuToggle = document.querySelector('.mobile-menu');
const mobileDropdown = document.querySelector('.mobile-menu-dropdown');
if (!menuToggle || !mobileDropdown) return; // Safety check
// Toggle dropdown visibility
menuToggle.addEventListener('click', (e) => {
e.stopPropagation(); // Prevent click from bubbling up
mobileDropdown.classList.toggle('active');
});
// Close dropdown when clicking outside
document.addEventListener('click', (e) => {
if (
mobileDropdown.classList.contains('active') &&
!mobileDropdown.contains(e.target) &&
!menuToggle.contains(e.target)
) {
mobileDropdown.classList.remove('active');
}
});
});
// Lazy load + scroll reveal
document.addEventListener("DOMContentLoaded", () => {
const lazyImages = document.querySelectorAll("img.lazy-image");
const fadeSections = document.querySelectorAll(".section-fade");
const observerOptions = {
threshold: 0.2,
rootMargin: "0px 0px 150px 0px"
};
const observer = new IntersectionObserver((entries, obs) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add("visible", "loaded");
obs.unobserve(entry.target);
}
});
}, observerOptions);
[...lazyImages, ...fadeSections].forEach(el => observer.observe(el));
});