Callback when element scrolls into view
const observeScroll = (element, callback) => {
const observer = new IntersectionObserver( ([entry]) => {
if (entry.intersectionRatio < 1) return;
callback(element);
observer.disconnect(); // Stop watching the element
},
{
threshold: 1
});
observer.observe(element); // Start watching the element
};
function startAnimation(element) { ... }
const element = document.getElementById("express-animation");
observeScroll(element, startAnimation);