From 7fcdbf872213c80edcc065ac6fde730fc418817a Mon Sep 17 00:00:00 2001 From: shenyu <448766534@qq.com> Date: Wed, 29 Jan 2020 20:36:48 +0800 Subject: [PATCH] fix: tocbot --- layout/_partial/after-footer.ejs | 5 ++++- source/css/_partial/tocbot.styl | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/layout/_partial/after-footer.ejs b/layout/_partial/after-footer.ejs index 90fc783..548613b 100644 --- a/layout/_partial/after-footer.ejs +++ b/layout/_partial/after-footer.ejs @@ -16,11 +16,14 @@ headingSelector: 'h1, h2, h3, h4, h5, h6', hasInnerContainers: true, scrollSmooth: true, + scrollContainer:'main', positionFixedSelector: '.tocbot', positionFixedClass: 'is-position-fixed', fixedSidebarOffset: 'auto', onClick: (e) => { - document.getElementById(e.target.innerText).scrollIntoView() + $('.toc-link').removeClass('is-active-link'); + $(`a[href=${e.target.hash}]`).addClass('is-active-link'); + $(e.target.hash).scrollIntoView(); return false; } }); diff --git a/source/css/_partial/tocbot.styl b/source/css/_partial/tocbot.styl index 14c0fe8..bdc642b 100644 --- a/source/css/_partial/tocbot.styl +++ b/source/css/_partial/tocbot.styl @@ -1,6 +1,6 @@ .tocbot - position fixed + position absolute top 14rem left calc((100vw - 70rem) / 2 + 70rem) font-size 80% @@ -47,3 +47,9 @@ a.toc-link margin-top -1px position absolute width 2px + +.is-active-link::before + background-color sea-blue + +.is-active-link + font-weight 700 \ No newline at end of file