Account for hero not always existing

This is mostly true for the homepage
This commit is contained in:
Jake Howard 2022-08-02 22:03:08 +01:00
parent cdb037a9c8
commit 1b1971f09d
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -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");
});
if (HERO) {
window.addEventListener("resize", debounce(setHeroHeight, 2000));
window.addEventListener("scroll", throttle(handleHeroStuck, 100));
}