function animateHTML(){ var animatedBits; var windowHeight; function init(){ animatedBits = document.querySelectorAll('.scroll-triggered-bits'); windowHeight = window.innerHeight; } function checkPosition(){ for (var i = 0; i < animatedBits.length; i++){ var animatedBit = animatedBits[i]; var posFromTop = animatedBits[i].getBoundingClientRect().top; if(posFromTop - windowHeight <= 0){ animatedBit.classList.add('animate-bits'); } } } window.addEventListener('scroll', checkPosition); window.addEventListener('resize', init); init(); checkPosition(); }
Zum Inhalt springen