document.addEventListener('DOMContentLoaded', function() {
// Check if element is in viewport
function isInViewport(element) {
const rect = element.getBoundingClientRect();
return (
rect.top <= (window.innerHeight || document.documentElement.clientHeight) * 0.8 && rect.bottom >= 0
);
}
// Get all elements to animate
const sections = document.querySelectorAll('.animate-section');
const images = document.querySelectorAll('.animate-image');
const contents = document.querySelectorAll('.animate-content');
// Function to check and animate elements
function checkElements() {
sections.forEach((section, index) => {
if (isInViewport(section) && !section.classList.contains('visible')) {
// Add animation classes with slight delay between elements
section.classList.add('visible');
// Animate child elements with delay
setTimeout(() => {
if (images[index]) images[index].classList.add('visible');
}, 200);
setTimeout(() => {
if (contents[index]) contents[index].classList.add('visible');
}, 400);
}
});
}
// Add scroll event listener
window.addEventListener('scroll', checkElements);
// Initial check (with a delay to ensure elements are rendered)
setTimeout(checkElements, 300);
// Also check when images might have loaded
window.addEventListener('load', function() {
checkElements();
});
});


Reviews
There are no reviews yet