From fea4cb356e5834a6b81cf9856e829e602edd6229 Mon Sep 17 00:00:00 2001 From: wheattoast11 Date: Sat, 30 Nov 2024 15:50:18 -0600 Subject: [PATCH] add cleanup for scroll effects --- src/ui/ScrollEffects.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ui/ScrollEffects.js b/src/ui/ScrollEffects.js index cc2d655..6387ce7 100644 --- a/src/ui/ScrollEffects.js +++ b/src/ui/ScrollEffects.js @@ -1,6 +1,8 @@ export class ScrollEffects { constructor() { this.init(); + this.setupParallax(); + this.observers = []; } init() { @@ -24,6 +26,7 @@ export class ScrollEffects { document.querySelectorAll('.section, [data-parallax]').forEach(el => { observer.observe(el); }); + this.observers.push(observer); } setupParallaxForElement(element) { @@ -37,6 +40,12 @@ export class ScrollEffects { window.addEventListener('scroll', handleScroll); } + + dispose() { + this.observers.forEach(observer => observer.disconnect()); + this.observers = []; + window.removeEventListener('scroll', this.handleScroll); + } } function buildThresholdList() {