Vandevliet.AerialShots.Website/public/assets/js/header.js

34 lines
813 B
JavaScript
Raw Normal View History

2024-06-12 16:41:06 +02:00
window.addEventListener('scroll', () =>
{
// Add class to body when scrolled.
document.body.classList.toggle('is-scrolled', window.scrollY > 0);
// Parallax effect.
/**
* @type {HTMLVideoElement}
*/
const heroVid = document.querySelector('.hero video');
heroVid.style.top = `${window.scrollY / 3}px`;
// Highlight menu item when scrolled to section.
let current = '';
document.querySelectorAll('.section').forEach(section =>
{
const sectionTop = section.offsetTop;
if (window.scrollY >= sectionTop - 70)
{
current = section.getAttribute('id');
}
});
document.querySelectorAll('.nav-link').forEach(link =>
{
link.classList.remove('active');
if (link.getAttribute('href') === `#${current}`)
{
link.classList.add('active');
}
});
});