Skip to content

Commit

Permalink
Fixed back-to-top button when using instant loading
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed Mar 14, 2023
1 parent a7c1d06 commit 9752ad2
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 14 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.

8 changes: 4 additions & 4 deletions material/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
{% endif %}
{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.7bf56d0a.min.css' | url }}">
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.c4a75a56.min.css' | url }}">
{% if config.theme.palette %}
{% set palette = config.theme.palette %}
<link rel="stylesheet" href="{{ 'assets/stylesheets/palette.a0c5b2b5.min.css' | url }}">
Expand Down Expand Up @@ -183,10 +183,10 @@
{% include "partials/javascripts/content.html" %}
</div>
{% if "navigation.top" in features %}
<a href="#" class="md-top md-icon" data-md-component="top" hidden>
<button type="button" class="md-top md-icon" data-md-component="top" hidden>
{% include ".icons/material/arrow-up.svg" %}
{{ lang.t("top") }}
</a>
</button>
{% endif %}
</main>
{% block footer %}
Expand Down Expand Up @@ -240,7 +240,7 @@
</script>
{% endblock %}
{% block scripts %}
<script src="{{ 'assets/javascripts/bundle.fc8c2696.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.efa0ade1.min.js' | url }}"></script>
{% for path in config.extra_javascript %}
<script src="{{ path | url }}"></script>
{% endfor %}
Expand Down
8 changes: 8 additions & 0 deletions src/assets/javascripts/components/top/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
distinctUntilKeyChanged,
endWith,
finalize,
fromEvent,
ignoreElements,
map,
repeat,
Expand Down Expand Up @@ -166,6 +167,13 @@ export function mountBackToTop(
el.style.top = `${height + 16}px`
})

/* Go back to top */
fromEvent(el, "click")
.subscribe(ev => {
ev.preventDefault()
window.scrollTo({ top: 0 })
})

/* Create and return component */
return watchBackToTop(el, { viewport$, main$, target$ })
.pipe(
Expand Down
1 change: 1 addition & 0 deletions src/assets/stylesheets/main/components/_top.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
margin-inline-start: 50%;
font-size: px2rem(14px);
color: var(--md-default-fg-color--light);
cursor: pointer;
background-color: var(--md-default-bg-color);
border-radius: px2rem(32px);
outline: none;
Expand Down
6 changes: 3 additions & 3 deletions src/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,15 @@

<!-- Back-to-top button -->
{% if "navigation.top" in features %}
<a
href="#"
<button
type="button"
class="md-top md-icon"
data-md-component="top"
hidden
>
{% include ".icons/material/arrow-up.svg" %}
{{ lang.t("top") }}
</a>
</button>
{% endif %}
</main>

Expand Down

0 comments on commit 9752ad2

Please sign in to comment.