forked from nulang-org/nulang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScrollReveal.astro
More file actions
32 lines (31 loc) · 1.14 KB
/
Copy pathScrollReveal.astro
File metadata and controls
32 lines (31 loc) · 1.14 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
<div aria-hidden="true" style="display:none"></div>
<script>
// Scroll-triggered entrance animations for benefit rows and callout
function initScrollAnimations() {
const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (reducedMotion) {
document.querySelectorAll('.benefit-row, .benefit-callout').forEach(el => el.classList.add('visible'));
return;
}
const elements = document.querySelectorAll('.benefit-row, .benefit-callout');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, { threshold: 0.1 });
elements.forEach(el => observer.observe(el));
// Also reveal any elements already in the viewport on load
setTimeout(() => {
elements.forEach(el => {
const rect = el.getBoundingClientRect();
if (rect.top < window.innerHeight && rect.bottom > 0) {
el.classList.add('visible');
observer.unobserve(el);
}
});
}, 100);
}
</script>