Vandevliet.AerialShots.Website/src/js/scripts.js

62 lines
1.7 KiB
JavaScript
Raw Normal View History

window.addEventListener('pageshow', () =>
2024-06-13 14:26:33 +02:00
{
2024-07-13 18:09:28 +02:00
/**
* @type {NodeListOf<HTMLVideoElement>}
*/
const parallaxElems = document.querySelectorAll('.parallax');
2024-06-13 14:26:33 +02:00
const refreshScrollLinkedPositioningEffect = () =>
{
2024-07-13 18:09:28 +02:00
document.body.classList.toggle('is-scrolled', window.scrollY > 0);
parallaxElems.forEach(parallaxElem =>
{
const parentElem = parallaxElem.parentElement;
2024-07-13 18:09:28 +02:00
const parentRect = parentElem.getBoundingClientRect();
const parentScroll = parentRect.top + (parentRect.height / 2);
2024-07-13 18:09:28 +02:00
const windowScroll = window.scrollY + (window.innerHeight / 2);
2024-07-13 18:09:28 +02:00
parallaxElem.style.top = `${(windowScroll - parentScroll) / 4}px`;
});
};
refreshScrollLinkedPositioningEffect();
window.addEventListener('scroll', refreshScrollLinkedPositioningEffect);
});
2024-06-13 14:26:33 +02:00
document.addEventListener('DOMContentLoaded', () =>
{
2024-07-13 18:09:28 +02:00
/**
* @type {NodeListOf<HTMLElement>}
*/
const sectionsWithId = document.querySelectorAll('section[id]');
sectionsWithId.forEach(anchorTarget =>
2024-06-13 14:26:33 +02:00
{
const anchorHeader = anchorTarget.querySelector('h1,h2');
2024-07-29 17:17:52 +02:00
if (anchorHeader)
2024-07-13 18:09:28 +02:00
{
2024-07-29 17:17:52 +02:00
const anchorLink = document.createElement('a');
anchorLink.className = 'anchor-link';
anchorLink.href = `#${anchorTarget.id}`;
anchorLink.innerHTML = ' #&nbsp;';
anchorHeader.appendChild(anchorLink);
2024-07-13 18:09:28 +02:00
}
});
2025-05-24 18:47:24 +02:00
// Collapse the navbar in mobile view after clicking a link.
document.querySelectorAll('#navbarNav li.nav-item>a').forEach(navLink =>
{
2025-05-24 18:47:24 +02:00
navLink.addEventListener('click', () =>
2024-07-13 18:09:28 +02:00
{
/**
* @type {HTMLButtonElement}
*/
const navbarNav = document.querySelector('button.navbar-toggler[aria-expanded="true"]');
navbarNav?.click();
});
});
2024-06-13 14:26:33 +02:00
});