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

@ -34,7 +34,7 @@
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block styles %} {% block styles %}
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.c382b1dc.min.css' | url }}"> <link rel="stylesheet" href="{{ 'assets/stylesheets/main.1c3799f8.min.css' | url }}">
{% if config.theme.palette %} {% if config.theme.palette %}
{% set palette = config.theme.palette %} {% set palette = config.theme.palette %}
<link rel="stylesheet" href="{{ 'assets/stylesheets/palette.cc9b2e1e.min.css' | url }}"> <link rel="stylesheet" href="{{ 'assets/stylesheets/palette.cc9b2e1e.min.css' | url }}">
@ -214,7 +214,7 @@
</script> </script>
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<script src="{{ 'assets/javascripts/bundle.efad133d.min.js' | url }}"></script> <script src="{{ 'assets/javascripts/bundle.8a488aaa.min.js' | url }}"></script>
{% for path in config["extra_javascript"] %} {% for path in config["extra_javascript"] %}
<script src="{{ path | url }}"></script> <script src="{{ path | url }}"></script>
{% endfor %} {% endfor %}

View File

@ -32,6 +32,8 @@ import {
map, map,
switchMap, switchMap,
take, take,
takeLast,
takeUntil,
tap, tap,
throttleTime throttleTime
} from "rxjs" } from "rxjs"
@ -42,7 +44,8 @@ import {
getElementSize, getElementSize,
watchElementContentOffset, watchElementContentOffset,
watchElementFocus, watchElementFocus,
watchElementOffset watchElementOffset,
watchElementVisibility
} from "~/browser" } from "~/browser"
import { Component } from "../../../_" 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 */ /* Track relative origin of tooltip */
push$ push$
.pipe( .pipe(

View File

@ -186,12 +186,15 @@
transition: transition:
color 250ms, color 250ms,
background-color 250ms; background-color 250ms;
animation: pulse 2000ms infinite;
content: ""; content: "";
// [reduced motion]: Disable animation // [reduced motion]: Disable animation
@media (prefers-reduced-motion) { @media not all and (prefers-reduced-motion) {
animation: none;
// Annotation marker is visible
[data-md-visible] > & {
animation: pulse 2000ms infinite;
}
} }
// Annotation marker on focus/hover // Annotation marker on focus/hover