feat: support vertical scrolling for toc in desktop mode (#2064)

This commit is contained in:
Cotes Chung 2024-11-28 02:58:25 +08:00
parent 11647697bb
commit 5265b03974
No known key found for this signature in database
GPG key ID: 0D9E54843167A808
5 changed files with 61 additions and 13 deletions

View file

@ -1,8 +1,9 @@
{% include toc-status.html %} {% include toc-status.html %}
{% if enable_toc %} {% if enable_toc %}
<section id="toc-wrapper" class="ps-0 pe-4"> <div class="toc-border-cover z-3"></div>
<h2 class="panel-heading ps-3 mb-2">{{- site.data.locales[include.lang].panel.toc -}}</h2> <section id="toc-wrapper" class="position-sticky ps-0 pe-4">
<h2 class="panel-heading ps-3 pb-2 mb-0">{{- site.data.locales[include.lang].panel.toc -}}</h2>
<nav id="toc"></nav> <nav id="toc"></nav>
</section> </section>
{% endif %} {% endif %}

View file

@ -33,7 +33,7 @@ layout: compress
</main> </main>
<!-- panel --> <!-- panel -->
<aside aria-label="Panel" id="panel-wrapper" class="col-xl-3 ps-2 mb-5 text-muted"> <aside aria-label="Panel" id="panel-wrapper" class="col-xl-3 ps-2 text-muted">
<div class="access"> <div class="access">
{% include_cached update-list.html lang=lang %} {% include_cached update-list.html lang=lang %}
{% include_cached trending-tags.html lang=lang %} {% include_cached trending-tags.html lang=lang %}

View file

@ -154,3 +154,7 @@
%max-w-100 { %max-w-100 {
max-width: 100%; max-width: 100%;
} }
%panel-border {
border-left: 1px solid var(--main-border-color);
}

View file

@ -6,7 +6,6 @@
top: 2rem; top: 2rem;
transition: top 0.2s ease-in-out; transition: top 0.2s ease-in-out;
margin-top: 3rem; margin-top: 3rem;
margin-bottom: 4rem;
&:only-child { &:only-child {
position: -webkit-sticky; position: -webkit-sticky;
@ -14,11 +13,12 @@
} }
> section { > section {
padding-left: 1rem; @extend %panel-border;
border-left: 1px solid var(--main-border-color);
&:not(:last-child) { padding-left: 1rem;
margin-bottom: 4rem;
&:not(:first-child) {
margin-top: 4rem;
} }
} }
@ -48,6 +48,10 @@
} }
} }
> :last-child {
margin-bottom: 4rem;
}
@include bp.lt(bp.get(xl)) { @include bp.lt(bp.get(xl)) {
display: none; display: none;
} }

View file

@ -246,14 +246,26 @@ header {
} }
/* TOC panel */ /* TOC panel */
#toc-wrapper {
border-left: 1px solid rgba(158, 158, 158, 0.17); %top-cover {
position: -webkit-sticky; content: '';
display: block;
position: sticky; position: sticky;
top: 4rem; top: 0;
width: 100%;
height: 3rem;
background: linear-gradient(var(--main-bg) 50%, transparent);
}
#toc-wrapper {
top: 0;
transition: top 0.2s ease-in-out; transition: top 0.2s ease-in-out;
-webkit-animation: fade-up 0.8s; -webkit-animation: fade-up 0.8s;
animation: fade-up 0.8s; animation: fade-up 0.8s;
overflow-y: auto;
max-height: calc(100vh - 2rem);
scrollbar-width: none;
margin-top: 2rem;
ul { ul {
list-style: none; list-style: none;
@ -266,6 +278,10 @@ header {
margin: 0.4rem 0; margin: 0.4rem 0;
} }
&:first-child {
margin-top: 0;
}
a { a {
padding: 0.2rem 0 0.2rem 1.25rem; padding: 0.2rem 0 0.2rem 1.25rem;
} }
@ -295,7 +311,6 @@ header {
&::before { &::before {
display: inline-block; display: inline-block;
width: 1px; width: 1px;
left: -1px;
height: 1.25rem; height: 1.25rem;
background-color: var(--toc-highlight) !important; background-color: var(--toc-highlight) !important;
} }
@ -305,6 +320,30 @@ header {
padding-left: 0.75rem; padding-left: 0.75rem;
} }
} }
@at-root .toc-border-cover {
@extend %top-cover;
margin-bottom: -4rem;
}
&::before {
@extend %top-cover;
}
&::after {
content: '';
position: fixed;
bottom: 0;
width: 15%;
height: 3.25rem;
margin-left: -1px;
background: linear-gradient(transparent, var(--main-bg) 70%);
}
> * {
@extend %panel-border;
}
} }
/* --- TOC button, bar and popup in mobile/tablet --- */ /* --- TOC button, bar and popup in mobile/tablet --- */