Category Stories
top
document.addEventListener('scroll', () = { const section = document.querySelector('.scroll-fade-section'); if (section) { const sectionTop = section.getBoundingClientRect().top; const sectionHeight = section.offsetHeight; const windowHeight = window.innerHeight; // Calculate the scroll position as a percentage const scrollPosition = Math.max(0, Math.min(1, 1 - sectionTop / (windowHeight + sectionHeight))); // Set the opacity based on scroll position section.style.opacity = scrollPosition; } });