var headerBackground = true; function updateScroll(checkHeight) { if (checkHeight) { if (headerBackground) document.querySelector("header").style.background = "black"; headerBackground = false; } else { if (!headerBackground) document.querySelector("header").style.background = ""; headerBackground = true; } } window.addEventListener("scroll", function() { updateScroll(window.scrollY > this.innerHeight * 0.27); }); var fixedContent = document.querySelector(".body.body-fixed"); if (fixedContent) fixedContent.addEventListener("scroll", function() { updateScroll(this.scrollTop > this.clientHeight * 0.27); });