-
Notifications
You must be signed in to change notification settings - Fork 25
/
spearker_card.js
30 lines (25 loc) · 915 Bytes
/
spearker_card.js
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
// Function to check if an element is in the viewport
function isElementInViewport(el) {
const rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
// Function to handle the scroll event
function handleScroll() {
const cards = document.querySelectorAll('.speaker-card');
cards.forEach((card) => {
if (isElementInViewport(card)) {
card.classList.add('show');
} else {
card.classList.remove('show');
}
});
}
// Attach an event listener for the scroll event
window.addEventListener('scroll', handleScroll);
// Initially check the elements in view on page load
document.addEventListener('DOMContentLoaded', handleScroll);