2022-06-20 08:46:42 +01:00
|
|
|
const Elevator = require("elevator.js");
|
2022-07-04 22:17:46 +01:00
|
|
|
const debounce = require("lodash.debounce");
|
2022-07-20 22:39:35 +01:00
|
|
|
const throttle = require("lodash.throttle");
|
2022-07-04 22:17:46 +01:00
|
|
|
|
|
|
|
const HERO = document.querySelector("section.hero");
|
|
|
|
const ROOT = document.querySelector(":root");
|
|
|
|
|
|
|
|
function getHeroHeight() {
|
|
|
|
return HERO.getBoundingClientRect().height;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setHeroHeight() {
|
|
|
|
ROOT.style.setProperty("--hero-height", `${getHeroHeight()}px`);
|
|
|
|
}
|
2022-06-20 08:46:42 +01:00
|
|
|
|
2022-07-20 22:39:35 +01:00
|
|
|
function handleHeroStuck() {
|
|
|
|
if (HERO.getBoundingClientRect().top === 0) {
|
|
|
|
HERO.classList.add("stuck");
|
|
|
|
} else {
|
|
|
|
HERO.classList.remove("stuck");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-12 21:08:37 +01:00
|
|
|
window.addEventListener("load", () => {
|
2022-06-12 17:21:46 +01:00
|
|
|
const navbarBurger = document.getElementById("navbar-burger");
|
|
|
|
const navbar = document.getElementById("navbar");
|
|
|
|
|
|
|
|
navbarBurger.addEventListener("click", () => {
|
2022-06-12 19:35:06 +01:00
|
|
|
navbarBurger.classList.toggle("is-active");
|
|
|
|
navbar.classList.toggle("is-active");
|
|
|
|
});
|
2022-06-19 17:10:35 +01:00
|
|
|
|
2022-06-20 08:46:42 +01:00
|
|
|
document.querySelectorAll(".scroll-top").forEach((element) => {
|
|
|
|
element.addEventListener("click", () => {
|
|
|
|
window.scrollTo({ top: 0, behavior: "smooth" });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-07-04 22:17:46 +01:00
|
|
|
document.querySelectorAll("#table-of-contents li a").forEach((element) => {
|
|
|
|
element.addEventListener("click", (event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
const rect = document
|
|
|
|
.querySelector(event.target.hash)
|
|
|
|
.getBoundingClientRect();
|
|
|
|
const top = rect.top - getHeroHeight();
|
|
|
|
window.scrollBy({ top: top, behavior: "smooth" });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-06-20 08:46:42 +01:00
|
|
|
const elevatorButton = document.getElementById("to-top-elevator");
|
|
|
|
new Elevator({
|
|
|
|
element: elevatorButton,
|
|
|
|
mainAudio: elevatorButton.dataset.mainAudio,
|
|
|
|
endAudio: elevatorButton.dataset.endAudio,
|
|
|
|
preloadAudio: false,
|
2022-06-19 17:10:35 +01:00
|
|
|
});
|
2022-06-12 17:21:46 +01:00
|
|
|
});
|
2022-07-04 22:17:46 +01:00
|
|
|
|
|
|
|
window.addEventListener("resize", debounce(setHeroHeight, 2000));
|
|
|
|
window.addEventListener("load", setHeroHeight);
|
2022-07-20 22:39:35 +01:00
|
|
|
|
|
|
|
window.addEventListener("scroll", throttle(handleHeroStuck, 100));
|