diff --git a/public/assets/js/header.js b/public/assets/js/header.js index 3c96161..2db5a8e 100644 --- a/public/assets/js/header.js +++ b/public/assets/js/header.js @@ -1,4 +1,34 @@ 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'); + } + }); }); \ No newline at end of file