function animateOnLoad (el) { el.classList.add('loaded'); } // Create the observer to call when an element appears in the view. const observer = new IntersectionObserver(entries => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('is-visible'); return; } // entry.target.classList.remove('is-visible'); }); }); function onDomLoaded () { document.querySelectorAll('.on-load').forEach(animateOnLoad); document.querySelectorAll('.on-visible').forEach((element) => observer.observe(element)); } $(document).ready( onDomLoaded )