Skip to content

Commit 2c56642

Browse files
authored
Merge pull request #2932 from IZUMIRU/toc-scroll
Add scroll to active toc
2 parents 3ea84c7 + 2850502 commit 2c56642

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

_includes/sidebar-toc-multipage-overview.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% assign pagetype = page.type %}
22
<div class="content-nav">
3-
<div class="inner-box sidebar-toc-wrapper {% if pagetype %}book{% endif %}" style="">
3+
<div class="inner-box sidebar-toc-wrapper" style="">
44
<h5 class="contents">Contents</h5>
55
{% if pagetype %}
66
<div class="inner-toc book" id="sidebar-toc">

_sass/layout/toc.scss

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
display: none;
1616
}
1717

18-
// disable floating for the book, since the TOC can become very large
19-
&.book {
20-
position: relative;
21-
}
22-
2318
.contents {
2419
font-weight: 700;
2520
}
@@ -28,14 +23,11 @@
2823
.inner-toc {
2924
max-height: 60vh;
3025
overflow-y: auto;
26+
position: relative;
3127

3228
@include bp(large) {
3329
max-height: none;
3430
}
35-
36-
&.book {
37-
max-height: none;
38-
}
3931
}
4032

4133
#toc {

resources/js/functions.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ $(document).ready(function() {
282282
autoId: true,
283283
numerate: false
284284
});
285+
const target = $('#sidebar-toc .active');
286+
if (target.length) {
287+
const marginTop = $('#sidebar-toc .type-chapter').length ? 15 : 10;
288+
$('#sidebar-toc').animate({scrollTop: target.position().top - marginTop}, 200);
289+
};
285290
}
286291
});
287292

0 commit comments

Comments
 (0)