Also refresh scroll effect on (re)load.

This commit is contained in:
Bob Vandevliet 2025-05-24 17:59:29 +02:00
parent 3f451c9936
commit 40da2349bf

View file

@ -1,17 +1,14 @@
document.addEventListener('DOMContentLoaded', () => window.addEventListener('pageshow', () =>
{ {
/** /**
* @type {NodeListOf<HTMLVideoElement>} * @type {NodeListOf<HTMLVideoElement>}
*/ */
const parallaxElems = document.querySelectorAll('.parallax'); const parallaxElems = document.querySelectorAll('.parallax');
// Handle scroll events. const refreshScrollLinkedPositioningEffect = () =>
window.addEventListener('scroll', () =>
{ {
// Add class to body when scrolled.
document.body.classList.toggle('is-scrolled', window.scrollY > 0); document.body.classList.toggle('is-scrolled', window.scrollY > 0);
// Parallax effect.
parallaxElems.forEach(parallaxElem => parallaxElems.forEach(parallaxElem =>
{ {
const parentElem = parallaxElem.parentElement; const parentElem = parallaxElem.parentElement;
@ -23,8 +20,14 @@ document.addEventListener('DOMContentLoaded', () =>
parallaxElem.style.top = `${(windowScroll - parentScroll) / 4}px`; parallaxElem.style.top = `${(windowScroll - parentScroll) / 4}px`;
}); });
}); };
refreshScrollLinkedPositioningEffect();
window.addEventListener('scroll', refreshScrollLinkedPositioningEffect);
});
document.addEventListener('DOMContentLoaded', () =>
{
/** /**
* @type {NodeListOf<HTMLElement>} * @type {NodeListOf<HTMLElement>}
*/ */