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);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter