From a16f1c6eeac86a3306292e469d2e145a54ae7c67 Mon Sep 17 00:00:00 2001 From: "1152958806@qq.com" <1152958806@qq.com> Date: Fri, 13 Oct 2023 22:02:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=20TOC=20=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E5=90=8E=E7=9A=84=E5=AE=9A=E4=BD=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/assets/js/main.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/templates/assets/js/main.js b/templates/assets/js/main.js index e271c06c..29c6cf3b 100644 --- a/templates/assets/js/main.js +++ b/templates/assets/js/main.js @@ -152,13 +152,12 @@ document.addEventListener('DOMContentLoaded', function () { */ const tocFn = function () { const postContent = document.querySelector('.post-content'); - if (postContent == null) return; - - const headers = postContent.querySelectorAll('h1,h2,h3,h4,h5,h6'); + const titles = postContent.querySelectorAll('h1,h2,h3,h4,h5,h6'); // 没有 toc 目录,则直接移除 - if (headers.length === 0) { - document.getElementById("card-toc").remove(); + if (titles.length === 0 || !titles) { + const cardToc = document.getElementById("card-toc"); + cardToc?.remove(); const $mobileTocButton = document.getElementById("mobile-toc-button") if($mobileTocButton){ $('#mobile-toc-button').attr('style', 'display: none'); @@ -168,7 +167,11 @@ document.addEventListener('DOMContentLoaded', function () { tocSelector: '.toc-content', contentSelector: '.post-content', headingSelector: 'h1,h2,h3,h4,h5,h6', - hasInnerContainers: true + collapseDepth: 6, + headingsOffset: 70, + scrollSmooth: true, + scrollSmoothOffset: -70, + tocScrollOffset: 50 }); }