Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support vertical scrolling for TOC in desktop mode #2064

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 mb-5">
<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);
}
8 changes: 4 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
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