Skip to content

Commit 5e442eb

Browse files
committed
Reduced GPU cycles by only animating annotations when visible
1 parent 23cec7f commit 5e442eb

File tree

7 files changed

+30
-16
lines changed

7 files changed

+30
-16
lines changed

material/assets/javascripts/bundle.efad133d.min.js renamed to material/assets/javascripts/bundle.8a488aaa.min.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

material/assets/javascripts/bundle.efad133d.min.js.map renamed to material/assets/javascripts/bundle.8a488aaa.min.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

material/assets/stylesheets/main.c382b1dc.min.css renamed to material/assets/stylesheets/main.1c3799f8.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

material/assets/stylesheets/main.c382b1dc.min.css.map renamed to material/assets/stylesheets/main.1c3799f8.min.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

material/base.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
{% endif %}
3535
{% endblock %}
3636
{% block styles %}
37-
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.c382b1dc.min.css' | url }}">
37+
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.1c3799f8.min.css' | url }}">
3838
{% if config.theme.palette %}
3939
{% set palette = config.theme.palette %}
4040
<link rel="stylesheet" href="{{ 'assets/stylesheets/palette.cc9b2e1e.min.css' | url }}">
@@ -214,7 +214,7 @@
214214
</script>
215215
{% endblock %}
216216
{% block scripts %}
217-
<script src="{{ 'assets/javascripts/bundle.efad133d.min.js' | url }}"></script>
217+
<script src="{{ 'assets/javascripts/bundle.8a488aaa.min.js' | url }}"></script>
218218
{% for path in config["extra_javascript"] %}
219219
<script src="{{ path | url }}"></script>
220220
{% endfor %}

src/assets/javascripts/components/content/annotation/_/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import {
3232
map,
3333
switchMap,
3434
take,
35+
takeLast,
36+
takeUntil,
3537
tap,
3638
throttleTime
3739
} from "rxjs"
@@ -42,7 +44,8 @@ import {
4244
getElementSize,
4345
watchElementContentOffset,
4446
watchElementFocus,
45-
watchElementOffset
47+
watchElementOffset,
48+
watchElementVisibility
4649
} from "~/browser"
4750

4851
import { Component } from "../../../_"
@@ -128,6 +131,14 @@ export function mountAnnotation(
128131
}
129132
})
130133

134+
/* Start animation only when annotation is visible */
135+
const done$ = push$.pipe(takeLast(1))
136+
watchElementVisibility(el)
137+
.pipe(
138+
takeUntil(done$)
139+
)
140+
.subscribe(visible => el.toggleAttribute("data-md-visible", visible))
141+
131142
/* Track relative origin of tooltip */
132143
push$
133144
.pipe(

src/assets/stylesheets/main/layout/_tooltip.scss

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,15 @@
186186
transition:
187187
color 250ms,
188188
background-color 250ms;
189-
animation: pulse 2000ms infinite;
190189
content: "";
191190

192191
// [reduced motion]: Disable animation
193-
@media (prefers-reduced-motion) {
194-
animation: none;
192+
@media not all and (prefers-reduced-motion) {
193+
194+
// Annotation marker is visible
195+
[data-md-visible] > & {
196+
animation: pulse 2000ms infinite;
197+
}
195198
}
196199

197200
// Annotation marker on focus/hover

0 commit comments

Comments
 (0)