From 3b30901511ab706b33502fd24a793da3af09e3a5 Mon Sep 17 00:00:00 2001 From: shiyiya Date: Mon, 26 Sep 2022 17:14:18 +0800 Subject: [PATCH] . --- packages/ui/src/components/highlight.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/ui/src/components/highlight.ts b/packages/ui/src/components/highlight.ts index 9004c581..416dc0a7 100644 --- a/packages/ui/src/components/highlight.ts +++ b/packages/ui/src/components/highlight.ts @@ -34,6 +34,7 @@ export const highlightCls = $.css({ export default function (player: Player, container: HTMLElement, highlights: Highlight[] = []) { const $dom = document.createDocumentFragment() as unknown as HTMLDivElement let $highlights: HTMLDivElement[] = [] + let active = true function createDto(options: { left: number; text: string }) { const dto = $.create( @@ -56,10 +57,17 @@ export default function (player: Player, container: HTMLElement, highlights: Hig } player.on('videoinitialized', () => { - createHighlights(highlights, player.duration) + if (active) createHighlights(highlights, player.duration) }) player.on('videosourcechange', () => { + active = false $highlights.forEach((it) => it.remove()) }) + + player.on('highlightchange', () => { + active = true + $highlights.forEach((it) => it.remove()) + createHighlights(highlights, player.duration) + }) }