Skip to content

Commit 5265b03

Browse files
committed
feat: support vertical scrolling for toc in desktop mode (#2064)
1 parent 1164769 commit 5265b03

File tree

5 files changed

+60
-12
lines changed

5 files changed

+60
-12
lines changed

_includes/toc.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{% include toc-status.html %}
22

33
{% if enable_toc %}
4-
<section id="toc-wrapper" class="ps-0 pe-4">
5-
<h2 class="panel-heading ps-3 mb-2">{{- site.data.locales[include.lang].panel.toc -}}</h2>
4+
<div class="toc-border-cover z-3"></div>
5+
<section id="toc-wrapper" class="position-sticky ps-0 pe-4">
6+
<h2 class="panel-heading ps-3 pb-2 mb-0">{{- site.data.locales[include.lang].panel.toc -}}</h2>
67
<nav id="toc"></nav>
78
</section>
89
{% endif %}

_layouts/default.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</main>
3434

3535
<!-- panel -->
36-
<aside aria-label="Panel" id="panel-wrapper" class="col-xl-3 ps-2 mb-5 text-muted">
36+
<aside aria-label="Panel" id="panel-wrapper" class="col-xl-3 ps-2 text-muted">
3737
<div class="access">
3838
{% include_cached update-list.html lang=lang %}
3939
{% include_cached trending-tags.html lang=lang %}

_sass/abstracts/_placeholders.scss

+4
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,7 @@
154154
%max-w-100 {
155155
max-width: 100%;
156156
}
157+
158+
%panel-border {
159+
border-left: 1px solid var(--main-border-color);
160+
}

_sass/layout/_panel.scss

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
top: 2rem;
77
transition: top 0.2s ease-in-out;
88
margin-top: 3rem;
9-
margin-bottom: 4rem;
109

1110
&:only-child {
1211
position: -webkit-sticky;
1312
position: sticky;
1413
}
1514

1615
> section {
16+
@extend %panel-border;
17+
1718
padding-left: 1rem;
18-
border-left: 1px solid var(--main-border-color);
1919

20-
&:not(:last-child) {
21-
margin-bottom: 4rem;
20+
&:not(:first-child) {
21+
margin-top: 4rem;
2222
}
2323
}
2424

@@ -48,6 +48,10 @@
4848
}
4949
}
5050

51+
> :last-child {
52+
margin-bottom: 4rem;
53+
}
54+
5155
@include bp.lt(bp.get(xl)) {
5256
display: none;
5357
}

_sass/pages/_post.scss

+44-5
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,26 @@ header {
246246
}
247247

248248
/* TOC panel */
249-
#toc-wrapper {
250-
border-left: 1px solid rgba(158, 158, 158, 0.17);
251-
position: -webkit-sticky;
249+
250+
%top-cover {
251+
content: '';
252+
display: block;
252253
position: sticky;
253-
top: 4rem;
254+
top: 0;
255+
width: 100%;
256+
height: 3rem;
257+
background: linear-gradient(var(--main-bg) 50%, transparent);
258+
}
259+
260+
#toc-wrapper {
261+
top: 0;
254262
transition: top 0.2s ease-in-out;
255263
-webkit-animation: fade-up 0.8s;
256264
animation: fade-up 0.8s;
265+
overflow-y: auto;
266+
max-height: calc(100vh - 2rem);
267+
scrollbar-width: none;
268+
margin-top: 2rem;
257269

258270
ul {
259271
list-style: none;
@@ -266,6 +278,10 @@ header {
266278
margin: 0.4rem 0;
267279
}
268280

281+
&:first-child {
282+
margin-top: 0;
283+
}
284+
269285
a {
270286
padding: 0.2rem 0 0.2rem 1.25rem;
271287
}
@@ -295,7 +311,6 @@ header {
295311
&::before {
296312
display: inline-block;
297313
width: 1px;
298-
left: -1px;
299314
height: 1.25rem;
300315
background-color: var(--toc-highlight) !important;
301316
}
@@ -305,6 +320,30 @@ header {
305320
padding-left: 0.75rem;
306321
}
307322
}
323+
324+
@at-root .toc-border-cover {
325+
@extend %top-cover;
326+
327+
margin-bottom: -4rem;
328+
}
329+
330+
&::before {
331+
@extend %top-cover;
332+
}
333+
334+
&::after {
335+
content: '';
336+
position: fixed;
337+
bottom: 0;
338+
width: 15%;
339+
height: 3.25rem;
340+
margin-left: -1px;
341+
background: linear-gradient(transparent, var(--main-bg) 70%);
342+
}
343+
344+
> * {
345+
@extend %panel-border;
346+
}
308347
}
309348

310349
/* --- TOC button, bar and popup in mobile/tablet --- */

0 commit comments

Comments
 (0)