Skip to content

Commit

Permalink
Reduced GPU cycles by only animating annotations when visible
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed May 28, 2022
1 parent 23cec7f commit 5e442eb
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions material/base.html
Expand Up @@ -34,7 +34,7 @@
{% endif %}
{% endblock %}
{% 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 %}
{% set palette = config.theme.palette %}
<link rel="stylesheet" href="{{ 'assets/stylesheets/palette.cc9b2e1e.min.css' | url }}">
Expand Down Expand Up @@ -214,7 +214,7 @@
</script>
{% endblock %}
{% 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"] %}
<script src="{{ path | url }}"></script>
{% endfor %}
Expand Down
13 changes: 12 additions & 1 deletion src/assets/javascripts/components/content/annotation/_/index.ts
Expand Up @@ -32,6 +32,8 @@ import {
map,
switchMap,
take,
takeLast,
takeUntil,
tap,
throttleTime
} from "rxjs"
Expand All @@ -42,7 +44,8 @@ import {
getElementSize,
watchElementContentOffset,
watchElementFocus,
watchElementOffset
watchElementOffset,
watchElementVisibility
} from "~/browser"

import { Component } from "../../../_"
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 6 additions & 3 deletions src/assets/stylesheets/main/layout/_tooltip.scss
Expand Up @@ -186,12 +186,15 @@
transition:
color 250ms,
background-color 250ms;
animation: pulse 2000ms infinite;
content: "";

// [reduced motion]: Disable animation
@media (prefers-reduced-motion) {
animation: none;
@media not all and (prefers-reduced-motion) {

// Annotation marker is visible
[data-md-visible] > & {
animation: pulse 2000ms infinite;
}
}

// Annotation marker on focus/hover
Expand Down

0 comments on commit 5e442eb

Please sign in to comment.