💄 Fixed the TOC enable in global set & implement the auto follow in TOC list with content scroll.

This commit is contained in:
凡梦星尘
2022-10-06 10:02:19 +08:00
parent 48df6401d8
commit 0abad2539a
7 changed files with 85 additions and 31 deletions

View File

@@ -42,6 +42,7 @@
}
}
@if $toc_number {
.autonumber {
h2 {
counter-reset: h3;
@@ -66,6 +67,7 @@
content: counter(h2) "." counter(h3) "." counter(h4) ". ";
}
}
}
}
@import 'post-collapse';

View File

@@ -2,6 +2,10 @@
font-size: $font-size-small;
padding: 0 8px;
.active-current {
color: $orange;
}
ul {
list-style: none;
@@ -15,22 +19,22 @@
> ul {
border-left: 1px solid;
margin-left: 6px;
margin-left: 4px;
li {
position: relative;
padding-left: 0;
&:before {
position: absolute;
content: ' ';
top: 0.14em;
left: -0.75em;
width: 0.68em;
width: 0.65em;
height: 0.815em;
border-style: none none dashed none;
border-width: 0.05em;
}
}
}
}
@@ -42,10 +46,11 @@
a {
transition: all $transition-ease;
border: none;
&:before {
content: counters(item, ".") ". ";
counter-increment: item;
@if $toc_number {
&:before {
content: counters(item, ".") ". ";
counter-increment: item;
}
}
&:hover {

View File

@@ -70,6 +70,7 @@ $social_icons_only : {{ $P.socialIcons.iconsOnly }};
$social_icons_transition : {{ $P.socialIcons.transition }};
$links_settings_layout : {{ $P.linksSets.layout }};
$toc_enable : {{ $P.toc.enable }};
$toc_number : {{ $P.toc.number }};
$toc_expand_all : {{ $P.toc.expandAll }};
$toc_wrap : {{ $P.toc.wrap }};

View File

@@ -464,7 +464,13 @@ NexT.utils = {
},*/
registerSidebarTOC: function() {
this.sections = [...document.querySelectorAll('.post-toc li a.nav-link')].map(element => {
const toc = document.getElementById('TableOfContents');
if (!toc.hasChildNodes()) {
const tocActive = document.querySelector('.sidebar-inner');
tocActive.classList.remove('sidebar-nav-active', 'sidebar-toc-active');
tocActive.classList.add('sidebar-overview-active');
}
this.sections = [...document.querySelectorAll('.post-toc li a')].map(element => {
const target = document.getElementById(decodeURI(element.getAttribute('href')).replace('#', ''));
// TOC item animation navigate.
element.addEventListener('click', event => {
@@ -527,7 +533,7 @@ NexT.utils = {
},
activateNavByIndex: function(index) {
const target = document.querySelectorAll('.post-toc li a.nav-link')[index];
const target = document.querySelectorAll('.post-toc li a')[index];
if (!target || target.classList.contains('active-current')) return;
document.querySelectorAll('.post-toc .active').forEach(element => {