Account for hero not always existing
This is mostly true for the homepage
This commit is contained in:
parent
cdb037a9c8
commit
1b1971f09d
1 changed files with 7 additions and 3 deletions
|
@ -6,6 +6,9 @@ const HERO = document.querySelector("section.hero");
|
||||||
const ROOT = document.querySelector(":root");
|
const ROOT = document.querySelector(":root");
|
||||||
|
|
||||||
function getHeroHeight() {
|
function getHeroHeight() {
|
||||||
|
if (!HERO) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return HERO.getBoundingClientRect().height;
|
return HERO.getBoundingClientRect().height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +82,7 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||||
scrollToElement(scrollTarget, "auto");
|
scrollToElement(scrollTarget, "auto");
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener("resize", debounce(setHeroHeight, 2000));
|
if (HERO) {
|
||||||
|
window.addEventListener("resize", debounce(setHeroHeight, 2000));
|
||||||
window.addEventListener("scroll", throttle(handleHeroStuck, 100));
|
window.addEventListener("scroll", throttle(handleHeroStuck, 100));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue