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

59 lines
1.6 KiB
JavaScript
Raw Normal View History

2024-07-13 18:09:28 +02:00
document.addEventListener('DOMContentLoaded', () =>
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
2024-07-13 18:09:28 +02:00
// Handle scroll events.
window.addEventListener('scroll', () =>
{
2024-07-13 18:09:28 +02:00
// Add class to body when scrolled.
document.body.classList.toggle('is-scrolled', window.scrollY > 0);
// Parallax effect.
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`;
});
});
2024-06-13 14:26:33 +02:00
2024-07-13 18:09:28 +02:00
/**
* @type {NodeListOf<HTMLElement>}
*/
2024-07-29 17:17:52 +02:00
const sections = document.querySelectorAll('section');
2024-07-13 18:09:28 +02:00
sections.forEach(section =>
2024-06-13 14:26:33 +02:00
{
2024-07-29 17:17:52 +02:00
const anchorTarget = section.querySelector('[id^="section-"]');
const anchorHeader = section.querySelector('h1,h2');
if (anchorTarget && 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
}
});
document.querySelectorAll('#navbarNav li.nav-item>a').forEach(anchor =>
{
2024-07-13 18:09:28 +02:00
anchor.addEventListener('click', () =>
{
/**
* @type {HTMLButtonElement}
*/
const navbarNav = document.querySelector('button.navbar-toggler[aria-expanded="true"]');
navbarNav?.click();
});
});
2024-06-13 14:26:33 +02:00
});