From 1c19f9018d108fc630fcf6bf85a33e2fd3beeef7 Mon Sep 17 00:00:00 2001 From: D-Sketon <2055272094@qq.com> Date: Sun, 14 Jan 2024 19:32:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20toc=E6=BB=9A=E5=8A=A8=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 13 +++++++------ README.md | 15 ++++++++------- source/css/_partial/sidebar.styl | 1 + source/js/pjax_script.js | 9 +++++---- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/README.en.md b/README.en.md index 706515a..6b21b48 100644 --- a/README.en.md +++ b/README.en.md @@ -191,12 +191,12 @@ waline: lang: zh-CN locale: {} # https://waline.js.org/guide/features/i18n.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E8%AF%AD%E8%A8%80 emoji: - - https://unpkg.com/@waline/emojis@1.0.1/weibo - - https://unpkg.com/@waline/emojis@1.0.1/alus - - https://unpkg.com/@waline/emojis@1.0.1/bilibili - - https://unpkg.com/@waline/emojis@1.0.1/qq - - https://unpkg.com/@waline/emojis@1.0.1/tieba - - https://unpkg.com/@waline/emojis@1.0.1/tw-emoji + - https://unpkg.com/@waline/emojis@1.2.0/weibo + - https://unpkg.com/@waline/emojis@1.2.0/alus + - https://unpkg.com/@waline/emojis@1.2.0/bilibili + - https://unpkg.com/@waline/emojis@1.2.0/qq + - https://unpkg.com/@waline/emojis@1.2.0/tieba + - https://unpkg.com/@waline/emojis@1.2.0/tw-emoji meta: - nick - mail @@ -206,6 +206,7 @@ waline: - mail wordLimit: 0 pageSize: 10 + pageview: true ``` If based on [twikoo](https://twikoo.js.org) diff --git a/README.md b/README.md index 44c0483..bbda2c9 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ - [x] 加载动画 - [x] TOC - [x] 回到顶部 -- [x] 文章统计(仅 Valine) +- [x] 文章统计(仅 Valine 和 Waline) - [x] 鼠标烟花 - [x] pjax(实验性) - [x] pwa(实验性) @@ -208,12 +208,12 @@ waline: lang: zh-CN locale: {} # https://waline.js.org/guide/features/i18n.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E8%AF%AD%E8%A8%80 emoji: - - https://unpkg.com/@waline/emojis@1.0.1/weibo - - https://unpkg.com/@waline/emojis@1.0.1/alus - - https://unpkg.com/@waline/emojis@1.0.1/bilibili - - https://unpkg.com/@waline/emojis@1.0.1/qq - - https://unpkg.com/@waline/emojis@1.0.1/tieba - - https://unpkg.com/@waline/emojis@1.0.1/tw-emoji + - https://unpkg.com/@waline/emojis@1.2.0/weibo + - https://unpkg.com/@waline/emojis@1.2.0/alus + - https://unpkg.com/@waline/emojis@1.2.0/bilibili + - https://unpkg.com/@waline/emojis@1.2.0/qq + - https://unpkg.com/@waline/emojis@1.2.0/tieba + - https://unpkg.com/@waline/emojis@1.2.0/tw-emoji meta: - nick - mail @@ -223,6 +223,7 @@ waline: - mail wordLimit: 0 pageSize: 10 + pageview: true ``` 若基于 [twikoo](https://twikoo.js.org) diff --git a/source/css/_partial/sidebar.styl b/source/css/_partial/sidebar.styl index 3f1341f..2e73f56 100644 --- a/source/css/_partial/sidebar.styl +++ b/source/css/_partial/sidebar.styl @@ -383,6 +383,7 @@ $menu-link font-family: font-icon box-shadow: 1px 2px 10px rgba(0, 0, 0, 0.2) z-index: 999 + transition: all 0.3s ease img transition: all 0.3s ease diff --git a/source/js/pjax_script.js b/source/js/pjax_script.js index 0a776ac..fa892f3 100644 --- a/source/js/pjax_script.js +++ b/source/js/pjax_script.js @@ -208,7 +208,7 @@ var scrollIntoViewAndWait = (element) => { const navItems = getComputedStyle(document.getElementById('sidebar')).display === 'block' ? $('#sidebar .sidebar-toc-wrapper li') : $('#mobile-nav .sidebar-toc-wrapper li'); - if (navItems.length === 0) return; + if (!navItems.length) return; let activeLock = null; @@ -227,7 +227,7 @@ var scrollIntoViewAndWait = (element) => { anchorScroll(e); }); const anchor = $(decodeURI(link.attr('href'))); - if (!anchor) return null; + if (!anchor.length) return null; const alink = anchor.children('a'); alink && alink.on('click', (e) => { anchorScroll(e); @@ -237,7 +237,8 @@ var scrollIntoViewAndWait = (element) => { const activateNavByIndex = (index) => { const target = $(navItems[index]); - if (!target) return; + + if (!target.length) return; if (target.hasClass('current')) return; $('.sidebar-toc-wrapper .active').removeClass('active current'); @@ -290,7 +291,7 @@ var scrollIntoViewAndWait = (element) => { } const observer = new IntersectionObserver((entries) => { - const index = findIndex(entries) + (window.diffY < 0 ? 1 : 0) + const index = findIndex(entries) + (window.diffY > 0 ? 1 : 0) if (activeLock === null) { activateNavByIndex(index) }