From 1b1971f09d9cdca0a1e105ff2fb42258099a4b40 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Tue, 2 Aug 2022 22:03:08 +0100 Subject: [PATCH] Account for hero not always existing This is mostly true for the homepage --- static/src/js/base.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/static/src/js/base.js b/static/src/js/base.js index acc333d..4a7dce7 100644 --- a/static/src/js/base.js +++ b/static/src/js/base.js @@ -6,6 +6,9 @@ const HERO = document.querySelector("section.hero"); const ROOT = document.querySelector(":root"); function getHeroHeight() { + if (!HERO) { + return 0; + } return HERO.getBoundingClientRect().height; } @@ -79,6 +82,7 @@ window.addEventListener("DOMContentLoaded", () => { scrollToElement(scrollTarget, "auto"); }); -window.addEventListener("resize", debounce(setHeroHeight, 2000)); - -window.addEventListener("scroll", throttle(handleHeroStuck, 100)); +if (HERO) { + window.addEventListener("resize", debounce(setHeroHeight, 2000)); + window.addEventListener("scroll", throttle(handleHeroStuck, 100)); +}