From e460649b57c3e4d059b970e48f9f04cc4c59132d Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Tue, 28 Sep 2021 18:13:00 +0100 Subject: [PATCH] Call overscrollColourFixer on initial page load --- chartered-frontend/src/overscrollColourFixer.ts | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/chartered-frontend/src/overscrollColourFixer.ts b/chartered-frontend/src/overscrollColourFixer.ts index 2a23da9..1701d96 100644 --- a/chartered-frontend/src/overscrollColourFixer.ts +++ a/chartered-frontend/src/overscrollColourFixer.ts @@ -6,19 +6,18 @@ window.addEventListener("load", () => { let ticking; - window.addEventListener( - "scroll", - function (event) { - if (!ticking) { - ticking = true; + const backgroundFix = () => { + if (!ticking) { + ticking = true; - window.requestAnimationFrame(() => { - document.documentElement.style.backgroundColor = - window.scrollY > 70 ? "var(--bs-primary)" : "#fff"; - ticking = false; - }); - } - }, - false - ); + window.requestAnimationFrame(() => { + document.documentElement.style.backgroundColor = + window.scrollY > 70 ? "var(--bs-primary)" : "#fff"; + ticking = false; + }); + } + }; + + window.addEventListener("scroll", backgroundFix, false); + backgroundFix(); }); -- rgit 0.1.3