watch.twip-network.org/scripts/pages/user/main.js
2024-01-25 15:57:36 +01:00

23 lines
817 B
JavaScript

document.addEventListener('DOMContentLoaded', function () {
var headerText = document.getElementById('headerText');
var h1 = document.querySelector('.user-index-h1');
var h2 = document.querySelector('.user-index-h2');
// Function to handle the scroll event
function handleScroll() {
// Calculate the opacity based on the scroll position
var scrollFraction = window.scrollY / (document.documentElement.scrollHeight - window.innerHeight);
var opacity = 1 - (scrollFraction*2);
// Apply the opacity to the elements
h1.style.opacity = opacity;
h2.style.opacity = opacity;
}
// Attach the handleScroll function to the scroll event
window.addEventListener('scroll', handleScroll);
// Initial check on page load
handleScroll();
});