Reduced GPU cycles by only animating annotations when visible

This commit is contained in:
squidfunk
2022-05-28 13:12:51 +02:00
parent 23cec7f441
commit 5e442eb46f
7 changed files with 30 additions and 16 deletions

View File

@@ -32,6 +32,8 @@ import {
map,
switchMap,
take,
takeLast,
takeUntil,
tap,
throttleTime
} from "rxjs"
@@ -42,7 +44,8 @@ import {
getElementSize,
watchElementContentOffset,
watchElementFocus,
watchElementOffset
watchElementOffset,
watchElementVisibility
} from "~/browser"
import { Component } from "../../../_"
@@ -128,6 +131,14 @@ export function mountAnnotation(
}
})
/* Start animation only when annotation is visible */
const done$ = push$.pipe(takeLast(1))
watchElementVisibility(el)
.pipe(
takeUntil(done$)
)
.subscribe(visible => el.toggleAttribute("data-md-visible", visible))
/* Track relative origin of tooltip */
push$
.pipe(