From 504cc6e54a2bc9591eac457cd3fb96cda3161829 Mon Sep 17 00:00:00 2001 From: Daniel Lorigan Date: Wed, 23 Oct 2024 16:37:18 -0700 Subject: [PATCH] Check scroll position on page load --- src/routes/+layout.svelte | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 0bace096..d89eb3a0 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -43,19 +43,20 @@ onMount(() => { window.onscroll = function() {scrollFunction()}; + scrollFunction(); }); function scrollFunction() { closeNav(); if (window.scrollY > 40) { - document.getElementById("nav-image").classList.add("scrolling"); + document.getElementById("nav-image")?.classList.add("scrolling"); document.getElementsByClassName("navbar")[0].classList.add("scrolling"); let es = document.getElementsByClassName("nav-text"); for(let i = 0; i < es.length; i++) { es[i].classList.add("scrolling"); } } else if (window.scrollY == 0) { - document.getElementById("nav-image").classList.remove("scrolling"); + document.getElementById("nav-image")?.classList.remove("scrolling"); document.getElementsByClassName("navbar")[0].classList.remove("scrolling"); let es = document.getElementsByClassName("nav-text"); for(let i = 0; i < es.length; i++) {