SAE_WEB22/script.js
2023-01-17 23:56:34 +01:00

15 lines
529 B
JavaScript

var content = document.getElementById("content");
var newText = document.getElementById("new-text");
window.addEventListener("scroll", function() {
var scrollTop = window.pageYOffset || document.documentElement.scrollTop;
if (scrollTop > 0) {
requestAnimationFrame(function() {
var opacity = Math.min(1, scrollTop / 500);
content.style.backgroundColor = "rgba(255, 255, 255, " + opacity + ")";
newText.style.opacity = opacity;
content.style.top = -scrollTop + "px";
});
}
});