From c4ed1926ceb2957869926c736a262616ae7f7c4d Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Fri, 16 Dec 2022 23:45:36 +0800 Subject: [PATCH] [opt] update --- source/css/_common/button.styl | 2 +- source/css/_layout/tag-plugins/note.styl | 2 +- source/css/_layout/widgets/search.styl | 2 +- source/js/main.js | 21 ++++++++++++++++++++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/source/css/_common/button.styl b/source/css/_common/button.styl index db74989..42d3593 100644 --- a/source/css/_common/button.styl +++ b/source/css/_common/button.styl @@ -32,7 +32,7 @@ a.button.start.gradient background: convert(hexo-config('style.gradient.start')) background-size: 1000% color: white - animation: glow 60s linear forwards + animation: glow 60s linear infinite @keyframes glow { from { background-position: 0% diff --git a/source/css/_layout/tag-plugins/note.styl b/source/css/_layout/tag-plugins/note.styl index 97bd0ef..3c49b88 100644 --- a/source/css/_layout/tag-plugins/note.styl +++ b/source/css/_layout/tag-plugins/note.styl @@ -3,6 +3,7 @@ padding: 0.25rem 1rem border-radius: $border-block background: var(--theme-bg2) + overflow: hidden if hexo-config('tag_plugins.note.border') == true border: 1px solid var(--theme-border) color: var(--text-p1) @@ -46,7 +47,6 @@ margin-top: .5rem .md-text .tag-plugin.note[child=iframe] - overflow: hidden padding: 0 >.body margin: 0 diff --git a/source/css/_layout/widgets/search.styl b/source/css/_layout/widgets/search.styl index 6d8d040..f9603e1 100644 --- a/source/css/_layout/widgets/search.styl +++ b/source/css/_layout/widgets/search.styl @@ -22,7 +22,7 @@ border-radius: 4px background: convert(hexo-config('style.gradient.search')) background-size: 200% - animation: glow 10s linear forwards + animation: glow 10s linear infinite @keyframes glow { from { background-position: 0% diff --git a/source/js/main.js b/source/js/main.js index 00f77e2..6598c24 100644 --- a/source/js/main.js +++ b/source/js/main.js @@ -95,6 +95,13 @@ const init = { $("article.md-text :header").each(function (idx, node) { segs.push(node) }); + // 定位到激活的目录树(不如pjax体验好) + // const widgets = document.querySelector('.widgets') + // const e1 = document.querySelector('.doc-tree-link.active') + // const offsetTop = e1.getBoundingClientRect().top - widgets.getBoundingClientRect().top - 100 + // if (offsetTop > 0) { + // widgets.scrollBy({top: offsetTop, behavior: 'smooth'}) + // } // 滚动 $(document, window).scroll(function (e) { var scrollTop = $(this).scrollTop(); @@ -114,7 +121,19 @@ const init = { $("#data-toc a.toc-link").removeClass("active") var link = "#" + topSeg.attr("id") if (link != '#undefined') { - $('#data-toc a.toc-link[href="' + encodeURI(link) + '"]').addClass("active") + const highlightItem = $('#data-toc a.toc-link[href="' + encodeURI(link) + '"]') + if (highlightItem.length > 0) { + highlightItem.addClass("active") + const e0 = document.querySelector('.widgets') + const e1 = document.querySelector('#data-toc a.toc-link[href="' + encodeURI(link) + '"]') + const offsetBottom = e1.getBoundingClientRect().bottom - e0.getBoundingClientRect().bottom + 100 + const offsetTop = e1.getBoundingClientRect().top - e0.getBoundingClientRect().top - 80 + if (offsetTop < 0) { + e0.scrollBy(0, offsetTop) + } else if (offsetBottom > 0) { + e0.scrollBy(0, offsetBottom) + } + } } else { $('#data-toc a.toc-link:first').addClass("active") }