window.addEventListener('pageshow', () => { /** * @type {NodeListOf} */ const parallaxElems = document.querySelectorAll('.parallax'); const refreshScrollLinkedPositioningEffect = () => { document.body.classList.toggle('is-scrolled', window.scrollY > 0); parallaxElems.forEach(parallaxElem => { const parentElem = parallaxElem.parentElement; const parentRect = parentElem.getBoundingClientRect(); const parentScroll = parentRect.top + (parentRect.height / 2); const windowScroll = window.scrollY + (window.innerHeight / 2); parallaxElem.style.top = `${(windowScroll - parentScroll) / 4}px`; }); }; refreshScrollLinkedPositioningEffect(); window.addEventListener('scroll', refreshScrollLinkedPositioningEffect); }); document.addEventListener('DOMContentLoaded', () => { /** * @type {NodeListOf} */ const sections = document.querySelectorAll('section'); sections.forEach(section => { const anchorTarget = section.querySelector('[id^="section-"]'); const anchorHeader = section.querySelector('h1,h2'); if (anchorTarget && anchorHeader) { const anchorLink = document.createElement('a'); anchorLink.className = 'anchor-link'; anchorLink.href = `#${anchorTarget.id}`; anchorLink.innerHTML = ' # '; anchorHeader.appendChild(anchorLink); } }); document.querySelectorAll('#navbarNav li.nav-item>a').forEach(anchor => { anchor.addEventListener('click', () => { /** * @type {HTMLButtonElement} */ const navbarNav = document.querySelector('button.navbar-toggler[aria-expanded="true"]'); navbarNav?.click(); }); }); });