2023-10-06 22:42:00 +01:00
|
|
|
require("lite-youtube-embed");
|
2022-09-02 17:18:40 +01:00
|
|
|
const GLightbox = require("glightbox");
|
2023-10-16 21:30:36 +01:00
|
|
|
const clamp = require("lodash.clamp");
|
2022-09-02 17:18:40 +01:00
|
|
|
|
2023-10-15 22:29:40 +01:00
|
|
|
const SCROLL_INDICATOR = document.getElementById("scroll-indicator");
|
|
|
|
const CONTENT = document.querySelector(".container.content");
|
|
|
|
|
2023-10-16 21:30:36 +01:00
|
|
|
function handleScrollIndicator() {
|
|
|
|
// How far down the page does the content start?
|
|
|
|
const initialScroll = CONTENT.getBoundingClientRect().top + window.scrollY;
|
|
|
|
|
|
|
|
const contentHeight = CONTENT.getBoundingClientRect().height;
|
|
|
|
|
|
|
|
// How far down the page do we consider the content "read"?
|
|
|
|
const scrollTarget = window.innerHeight * 0.75;
|
|
|
|
|
|
|
|
const scrolled =
|
|
|
|
(window.scrollY - initialScroll + scrollTarget) / contentHeight;
|
|
|
|
|
|
|
|
const scrolledPercentage = clamp(scrolled * 100, 0, 100);
|
|
|
|
|
|
|
|
SCROLL_INDICATOR.style.width = `${scrolledPercentage.toFixed(2)}%`;
|
|
|
|
}
|
|
|
|
|
2022-09-02 17:18:40 +01:00
|
|
|
window.addEventListener("load", () => {
|
2023-10-16 21:30:36 +01:00
|
|
|
window.addEventListener("resize", handleScrollIndicator);
|
|
|
|
window.addEventListener("scroll", handleScrollIndicator);
|
|
|
|
|
2022-09-02 17:18:40 +01:00
|
|
|
GLightbox({});
|
2023-10-15 22:29:40 +01:00
|
|
|
|
2023-10-16 21:30:36 +01:00
|
|
|
// Initialize the indicator
|
|
|
|
handleScrollIndicator();
|
2023-10-15 22:29:40 +01:00
|
|
|
});
|