Skip to content

Commit

Permalink
fix: toc滚动异常
Browse files Browse the repository at this point in the history
  • Loading branch information
D-Sketon committed Jan 14, 2024
1 parent e3d7079 commit 1c19f90
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
13 changes: 7 additions & 6 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -206,6 +206,7 @@ waline:
- mail
wordLimit: 0
pageSize: 10
pageview: true
```

If based on [twikoo](https://twikoo.js.org)
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
- [x] 加载动画
- [x] TOC
- [x] 回到顶部
- [x] 文章统计(仅 Valine)
- [x] 文章统计(仅 Valine 和 Waline
- [x] 鼠标烟花
- [x] pjax(实验性)
- [x] pwa(实验性)
Expand Down Expand Up @@ -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
Expand All @@ -223,6 +223,7 @@ waline:
- mail
wordLimit: 0
pageSize: 10
pageview: true
```

若基于 [twikoo](https://twikoo.js.org)
Expand Down
1 change: 1 addition & 0 deletions source/css/_partial/sidebar.styl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions source/js/pjax_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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');
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 1c19f90

Please sign in to comment.