20 lines
567 B
JavaScript
20 lines
567 B
JavaScript
function initScrollAnimations(elements) {
|
|
function checkVisibility(element) {
|
|
const rect = element.getBoundingClientRect();
|
|
return rect.top < window.innerHeight && rect.bottom >= 0;
|
|
}
|
|
|
|
function animateElements() {
|
|
elements.forEach(element => {
|
|
if (checkVisibility(element)) {
|
|
element.classList.add('visible');
|
|
}
|
|
});
|
|
}
|
|
|
|
window.addEventListener('scroll', animateElements);
|
|
|
|
// Initialer Aufruf für den Fall, dass Elemente bereits sichtbar sind
|
|
animateElements();
|
|
}
|