From 1f27c308c63729af356e1039a8133348464dc3f8 Mon Sep 17 00:00:00 2001 From: Benjamin Kane Date: Thu, 24 Oct 2024 15:05:03 -0400 Subject: [PATCH] update scroll reader --- app/packages/spotlight/src/createScrollReader.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/packages/spotlight/src/createScrollReader.ts b/app/packages/spotlight/src/createScrollReader.ts index dee64107f2..642df41ae6 100644 --- a/app/packages/spotlight/src/createScrollReader.ts +++ b/app/packages/spotlight/src/createScrollReader.ts @@ -15,14 +15,17 @@ export default function createScrollReader( let timeout: ReturnType; let zooming = false; - element.addEventListener("scroll", () => { + const scroll = () => { scrolling = true; - }); + }; + element.addEventListener("scroll", scroll); - element.addEventListener("scrollend", () => { + const scrollEnd = () => { scrolling = false; requestAnimationFrame(() => render(zooming, true)); - }); + }; + + element.addEventListener("scrollend", scrollEnd); const updateScrollStatus = () => { const threshold = getScrollSpeedThreshold(); @@ -68,7 +71,9 @@ export default function createScrollReader( return { destroy: () => { destroyed = true; + element.removeEventListener("scroll", scroll); + element.removeEventListener("scrollend", scrollEnd) }, - zooming: () => zooming + zooming: () => zooming, }; }