-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscroll-animation.js
More file actions
26 lines (21 loc) · 886 Bytes
/
Copy pathscroll-animation.js
File metadata and controls
26 lines (21 loc) · 886 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
document.addEventListener('DOMContentLoaded', () => {
const title = document.querySelector('.latest-events-title');
const section = document.querySelector('#upcoming-event-section');
let hasAnimated = false;
function checkScroll() {
if (hasAnimated) return;
const sectionTop = section.getBoundingClientRect().top;
const windowHeight = window.innerHeight;
// Start animation when section is 1/3 visible
if (sectionTop < windowHeight * 0.66) {
title.classList.add('animate');
hasAnimated = true;
// Remove event listener after animation starts
window.removeEventListener('scroll', checkScroll);
}
}
// Initial check in case section is already visible
checkScroll();
// Add scroll event listener
window.addEventListener('scroll', checkScroll);
});