SDG Cards JavaScript

PHOTO EMBED

Mon Oct 23 2023 18:16:16 GMT+0000 (Coordinated Universal Time)

Saved by @dannyholman #javascript

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);
content_copyCOPY