-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
31 lines (26 loc) · 1.11 KB
/
Copy pathscript.js
File metadata and controls
31 lines (26 loc) · 1.11 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
document.addEventListener("DOMContentLoaded", () => {
// Select all elements with scroll-based animation classes
const animatedElements = document.querySelectorAll(
".scroll-slide-up, .scroll-slide-left, .scroll-slide-right, .scroll-zoom"
);
// Observer options
const observerOptions = {
root: null, // Use the viewport as the root
threshold: 0.2, // Trigger when 20% of the element is visible
};
// IntersectionObserver callback
const observerCallback = (entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
// Add the 'active' class to trigger animation
entry.target.classList.add("active");
// Stop observing once the animation has been triggered
observer.unobserve(entry.target);
}
});
};
// Create and configure the IntersectionObserver
const observer = new IntersectionObserver(observerCallback, observerOptions);
// Observe each animated element
animatedElements.forEach(element => observer.observe(element));
});