-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfade.js
More file actions
41 lines (39 loc) · 1.46 KB
/
fade.js
File metadata and controls
41 lines (39 loc) · 1.46 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
33
34
35
36
37
38
39
40
41
document.addEventListener('DOMContentLoaded', () => {
// Create the observer
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
// Add or remove fade-in class based on visibility
if (entry.isIntersecting) {
entry.target.classList.add('fade-in-visible');
} else {
entry.target.classList.remove('fade-in-visible');
// Reset the opacity and transform when out of view
entry.target.style.opacity = '0';
if (entry.target.classList.contains('sponsor-item')) {
entry.target.style.transform = 'translateX(-50px)';
} else {
entry.target.style.transform = 'translateY(20px)';
}
}
});
}, {
threshold: 0.1,
rootMargin: '50px'
});
// Observe all elements with fade-in class
const fadeElements = document.querySelectorAll('.fade-in');
fadeElements.forEach(element => {
// Set initial state
element.style.opacity = '0';
observer.observe(element);
});
// Add visible class to elements already in view on load
setTimeout(() => {
fadeElements.forEach(element => {
const rect = element.getBoundingClientRect();
if (rect.top < window.innerHeight) {
element.classList.add('fade-in-visible');
}
});
}, 100);
});