document.addEventListener('DOMContentLoaded', function() {
// Team filters functionality with debounce
const filterButtons = document.querySelectorAll('.filter-btn');
const teamItems = document.querySelectorAll('.team-item');
// Debounce function to improve performance
function debounce(func, wait = 100) {
let timeout;
return function(...args) {
clearTimeout(timeout);
timeout = setTimeout(() => {
func.apply(this, args);
}, wait);
};
}
// Filter function with performance optimizations
const filterTeamItems = debounce((filterValue) => {
teamItems.forEach(item => {
if (filterValue === 'all' || item.classList.contains(filterValue)) {
item.style.display = 'block';
} else {
item.style.display = 'none';
}
});
});
// Add click event to filter buttons
filterButtons.forEach(button => {
button.addEventListener('click', function() {
const filterValue = this.getAttribute('data-filter');
// Remove active class from all buttons
filterButtons.forEach(btn => btn.classList.remove('active'));
// Add active class to clicked button
this.classList.add('active');
// Apply filtering with debounce
filterTeamItems(filterValue);
});
});
// Lazy load images that become visible
if ('IntersectionObserver' in window) {
const lazyImages = document.querySelectorAll('img[loading="lazy"]');
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.src; // Trigger actual loading
imageObserver.unobserve(img);
}
});
});
lazyImages.forEach(img => {
imageObserver.observe(img);
});
}
});