-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
27 lines (24 loc) · 1.01 KB
/
script.js
File metadata and controls
27 lines (24 loc) · 1.01 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
document.addEventListener('DOMContentLoaded', () => {
const options = {
root: null, // relative to the viewport
rootMargin: '0px',
threshold: 0.1 // 10% of the item must be visible
};
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
// If the element is intersecting (visible)
if (entry.isIntersecting) {
// Add the 'visible' class to trigger the animation
entry.target.classList.add('visible');
// Stop observing the element after it has become visible
observer.unobserve(entry.target);
}
});
}, options);
// Select all elements that should be animated on scroll
const animatedElements = document.querySelectorAll('.feature-card, .timeline li, .game-image, .element-card');
// Observe each animated element
animatedElements.forEach(el => {
observer.observe(el);
});
});