-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.js
More file actions
23 lines (22 loc) · 930 Bytes
/
app.js
File metadata and controls
23 lines (22 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
if (entry.target.classList.contains('hidden')) {
entry.target.classList.add('show'); // Action for .hidden elements
}
if (entry.target.classList.contains('animate')) {
entry.target.classList.add('active'); // Action for .animate elements
}
} else {
if (entry.target.classList.contains('hidden')) {
entry.target.classList.remove('show');
}
if (entry.target.classList.contains('animate')) {
entry.target.classList.remove('active');
}
}
});
}, { rootMargin: "0px 0px" });
// Select elements with different classes
const elements = document.querySelectorAll('.hidden, .animate');
elements.forEach((el) => observer.observe(el));