-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
92 lines (81 loc) · 2.87 KB
/
Copy pathscript.js
File metadata and controls
92 lines (81 loc) · 2.87 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
(() => {
'use strict';
// Scroll-triggered fade-in with stagger
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
},
{ threshold: 0.08, rootMargin: '0px 0px -60px 0px' }
);
document.querySelectorAll('.fade-in').forEach((el) => observer.observe(el));
// Navbar — transparent to solid on scroll
const nav = document.getElementById('nav');
if (nav) {
const onScroll = () => nav.classList.toggle('scrolled', window.scrollY > 40);
window.addEventListener('scroll', onScroll, { passive: true });
onScroll();
}
// Parallax on promo background images
const promos = document.querySelectorAll('.promo');
if (promos.length && window.matchMedia('(hover: hover)').matches) {
window.addEventListener('scroll', () => {
const scrollY = window.scrollY;
promos.forEach((promo) => {
const rect = promo.getBoundingClientRect();
const speed = 0.3;
const yPos = -(rect.top * speed);
promo.style.backgroundPositionY = yPos + 'px';
});
}, { passive: true });
}
// Mobile nav toggle
const toggle = document.getElementById('nav-toggle');
const links = document.getElementById('nav-links');
if (toggle && links) {
toggle.addEventListener('click', () => {
toggle.classList.toggle('active');
links.classList.toggle('open');
document.body.style.overflow = links.classList.contains('open') ? 'hidden' : '';
});
links.querySelectorAll('a').forEach((a) => {
a.addEventListener('click', () => {
toggle.classList.remove('active');
links.classList.remove('open');
document.body.style.overflow = '';
});
});
}
// FAQ accordion
document.querySelectorAll('.faq-question').forEach((btn) => {
btn.addEventListener('click', () => {
const item = btn.closest('.faq-item');
const isOpen = item.classList.contains('open');
document.querySelectorAll('.faq-item.open').forEach((openItem) => {
openItem.classList.remove('open');
openItem.querySelector('.faq-question').setAttribute('aria-expanded', 'false');
});
if (!isOpen) {
item.classList.add('open');
btn.setAttribute('aria-expanded', 'true');
}
});
});
// Smooth scroll offset for fixed nav
document.querySelectorAll('a[href^="#"]').forEach((a) => {
a.addEventListener('click', (e) => {
const href = a.getAttribute('href');
if (href === '#') return;
const target = document.querySelector(href);
if (!target) return;
e.preventDefault();
const offset = 80;
const top = target.getBoundingClientRect().top + window.scrollY - offset;
window.scrollTo({ top, behavior: 'smooth' });
});
});
})();