Skip to content

Commit

Permalink
feat: support vertical scrolling for toc in desktop mode (#2064)
Browse files Browse the repository at this point in the history
  • Loading branch information
cotes2020 committed Nov 27, 2024
1 parent 1164769 commit 5265b03
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 12 deletions.
5 changes: 3 additions & 2 deletions _includes/toc.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{% include toc-status.html %}

{% if enable_toc %}
<section id="toc-wrapper" class="ps-0 pe-4">
<h2 class="panel-heading ps-3 mb-2">{{- site.data.locales[include.lang].panel.toc -}}</h2>
<div class="toc-border-cover z-3"></div>
<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>
</section>
{% endif %}
2 changes: 1 addition & 1 deletion _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</main>

<!-- 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">
{% include_cached update-list.html lang=lang %}
{% include_cached trending-tags.html lang=lang %}
Expand Down
4 changes: 4 additions & 0 deletions _sass/abstracts/_placeholders.scss
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,7 @@
%max-w-100 {
max-width: 100%;
}

%panel-border {
border-left: 1px solid var(--main-border-color);
}
12 changes: 8 additions & 4 deletions _sass/layout/_panel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
top: 2rem;
transition: top 0.2s ease-in-out;
margin-top: 3rem;
margin-bottom: 4rem;

&:only-child {
position: -webkit-sticky;
position: sticky;
}

> section {
@extend %panel-border;

padding-left: 1rem;
border-left: 1px solid var(--main-border-color);

&:not(:last-child) {
margin-bottom: 4rem;
&:not(:first-child) {
margin-top: 4rem;
}
}

Expand Down Expand Up @@ -48,6 +48,10 @@
}
}

> :last-child {
margin-bottom: 4rem;
}

@include bp.lt(bp.get(xl)) {
display: none;
}
Expand Down
49 changes: 44 additions & 5 deletions _sass/pages/_post.scss
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,26 @@ header {
}

/* TOC panel */
#toc-wrapper {
border-left: 1px solid rgba(158, 158, 158, 0.17);
position: -webkit-sticky;

%top-cover {
content: '';
display: block;
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;
-webkit-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 {
list-style: none;
Expand All @@ -266,6 +278,10 @@ header {
margin: 0.4rem 0;
}

&:first-child {
margin-top: 0;
}

a {
padding: 0.2rem 0 0.2rem 1.25rem;
}
Expand Down Expand Up @@ -295,7 +311,6 @@ header {
&::before {
display: inline-block;
width: 1px;
left: -1px;
height: 1.25rem;
background-color: var(--toc-highlight) !important;
}
Expand All @@ -305,6 +320,30 @@ header {
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 --- */
Expand Down

0 comments on commit 5265b03

Please sign in to comment.