Also refresh scroll effect on (re)load.
This commit is contained in:
parent
3f451c9936
commit
40da2349bf
1 changed files with 9 additions and 6 deletions
|
|
@ -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>}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue