Skip to content

Commit

Permalink
add cleanup for scroll effects
Browse files Browse the repository at this point in the history
  • Loading branch information
wheattoast11 committed Nov 30, 2024
1 parent 0efb6d1 commit fea4cb3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/ui/ScrollEffects.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export class ScrollEffects {
constructor() {
this.init();
this.setupParallax();
this.observers = [];
}

init() {
Expand All @@ -24,6 +26,7 @@ export class ScrollEffects {
document.querySelectorAll('.section, [data-parallax]').forEach(el => {
observer.observe(el);
});
this.observers.push(observer);
}

setupParallaxForElement(element) {
Expand All @@ -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() {
Expand Down

0 comments on commit fea4cb3

Please sign in to comment.