From 51d6b7e9dd1621c07a3b5280e369a342b9811b18 Mon Sep 17 00:00:00 2001 From: Eric Mika Date: Mon, 18 Dec 2023 02:03:56 -0500 Subject: [PATCH] Cancel animation frames in Cubic Bezier preview. Fix for #18. --- src/cubic-bezier/view/cubic-bezier-preview.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cubic-bezier/view/cubic-bezier-preview.ts b/src/cubic-bezier/view/cubic-bezier-preview.ts index a15fb09..5e049b3 100644 --- a/src/cubic-bezier/view/cubic-bezier-preview.ts +++ b/src/cubic-bezier/view/cubic-bezier-preview.ts @@ -29,6 +29,7 @@ export class CubicBezierPreviewView implements View { private readonly value_: Value; private stopped_ = true; private startTime_ = -1; + private requestId_ = -1; constructor(doc: Document, config: Config) { this.onDispose_ = this.onDispose_.bind(this); @@ -71,10 +72,11 @@ export class CubicBezierPreviewView implements View { this.startTime_ = new Date().getTime() + PREVIEW_DELAY; this.stopped_ = false; - requestAnimationFrame(this.onTimer_); + this.requestId_ = requestAnimationFrame(this.onTimer_); } public stop(): void { + cancelAnimationFrame(this.requestId_); this.stopped_ = true; this.markerElem_.classList.remove(className('m', 'a')); } @@ -114,7 +116,7 @@ export class CubicBezierPreviewView implements View { } if (!this.stopped_) { - requestAnimationFrame(this.onTimer_); + this.requestId_ = requestAnimationFrame(this.onTimer_); } }