Skip to content

Commit a022aa7

Browse files
satnaingmiyayaLora
authored andcommitted
fix: improve back-to-top button to adapt layout changes properly (satnaing#527)
Update back-to-top button to accommodate properly, even if the max-width of the blog post is updated. Uses `fixed` position on mobile and `sticky` position on large screens. (cherry picked from commit 0cc647c)
1 parent 7513ade commit a022aa7

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

Lines changed: 8 additions & 0 deletions
Loading

src/components/BackToTopButton.astro

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,33 @@
11
---
22
import IconChevronLeft from "@/assets/icons/IconChevronLeft.svg";
3-
4-
/*
5-
In #btt-btn-container, left position is `left-[calc((var(--container-3xl)/2)+50%+1rem)]`.
6-
This is because we use `max-w-3xl` in `PostDetails.astro`.
7-
If `max-width` in `PostDetails.astro` get updated, make sure to update the `var(--container-3xl)` as well.
8-
max-w-3xl => var(--container-3xl)
9-
max-w-4xl => var(--container-4xl)
10-
max-w-5xl => var(--container-5xl)
11-
etc...
12-
*/
3+
import IconArrowNarrowUp from "@/assets/icons/IconArrowNarrowUp.svg";
134
---
145

156
<div
167
id="btt-btn-container"
178
class:list={[
18-
"fixed right-4 bottom-8 xl:right-auto xl:left-[calc((var(--container-3xl)/2)+50%+1rem)]",
19-
"translate-y-14 opacity-0 transition-all duration-500",
9+
"fixed right-4 bottom-8 z-50",
10+
"md:sticky md:right-auto md:float-end md:mr-1",
11+
"translate-y-14 opacity-0 transition duration-500",
2012
]}
2113
>
2214
<button
2315
data-button="back-to-top"
2416
class:list={[
25-
"group relative",
26-
"size-14 rounded-full px-2 py-1 shadow-xl lg:h-8 lg:w-fit lg:rounded-md lg:shadow-none",
27-
"bg-background lg:bg-transparent",
17+
"group relative bg-background px-2 py-1",
18+
"size-14 rounded-full shadow-xl",
19+
"md:h-8 md:w-fit md:rounded-md md:shadow-none",
20+
"md:bg-background/35 md:bg-clip-padding md:backdrop-blur-lg",
2821
]}
2922
>
3023
<span
3124
id="progress-indicator"
32-
class="absolute inset-0 -z-10 block size-14 scale-110 rounded-full bg-transparent lg:hidden lg:h-8 lg:rounded-md"
25+
class="absolute inset-0 -z-10 block size-14 scale-110 rounded-full bg-transparent md:hidden md:h-8 md:rounded-md"
3326
></span>
34-
<IconChevronLeft class="inline-block rotate-90 lg:hidden" />
35-
<span
36-
class="sr-only underline decoration-dashed decoration-2 underline-offset-4 group-hover:text-accent lg:not-sr-only"
37-
>
38-
<span class="text-xl" tabindex="0">&uarr;</span> Back To Top
27+
<IconChevronLeft class="inline-block rotate-90 md:hidden" />
28+
<span class="sr-only text-sm group-hover:text-accent md:not-sr-only">
29+
<IconArrowNarrowUp class="inline-block size-4" />
30+
Back To Top
3931
</span>
4032
</button>
4133
</div>

0 commit comments

Comments
 (0)