const text3 = document.querySelector('.text3'); const img3 = document.querySelector('.img3'); function animateElement(element, offset) { const elementPosition = element.getBoundingClientRect().top; const screenPosition = window.innerHeight / offset; if (elementPosition < screenPosition) { element.classList.add('animate'); } else { element.classList.remove('animate'); } } function animate() { animateElement(text3, 1.3); animateElement(img3, 1.3); } window.addEventListener('scroll', animate);