Skip to content

Commit abb98b1

Browse files
committed
【新增】优化导航按钮点击事件并添加外部链接打开优化
- 更新了导航按钮的 CSS 选择器,提高选择精度 - 添加了对内容区域外部链接的点击事件处理,实现新窗口打开 - 优化了平滑滚动的逻辑,修复了特定情况下的滚动问题
1 parent 05c15b0 commit abb98b1

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

index.html

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!doctype html>
22

33
<html>
4-
<markdown-html version="1.13.1" author="PJ568" repo="https://github.com/PJ-568/markdown.html"
4+
<markdown-html version="1.14.0" author="PJ568" repo="https://github.com/PJ-568/markdown.html"
55
license="CC BY-SA 4.0 International"></markdown-html>
66

77
<head>
@@ -601,15 +601,15 @@
601601
return;
602602
}
603603
}
604-
if (event.target.closest('.back-btn')) {
604+
if (event.target.closest('nav .back-btn')) {
605605
window.history.back();
606-
} else if (event.target.closest('.refresh-btn')) {
606+
} else if (event.target.closest('nav .refresh-btn')) {
607607
window.location.reload();
608-
} else if (event.target.closest('.dark-btn')) {
608+
} else if (event.target.closest('nav .dark-btn')) {
609609
darkmode.toggle();
610-
} else if (event.target.closest('.translate-switch')) {
610+
} else if (event.target.closest('nav .translate-switch')) {
611611
translate.changeLanguage(translate.language.getLocal());
612-
} else if (event.target.closest('a[href^="#"]')) {
612+
} else if (event.target.closest('.content a[href^="#"]')) {
613613
// 目录平滑移动
614614
const href = event.target.getAttribute('href');
615615
if (href !== '#') {
@@ -623,6 +623,13 @@
623623
console.error(`ID 为 ${targetId} 的元素不存在。`);
624624
}
625625
}
626+
} else if (event.target.closest('.content a:not([href$=".md"])')) {
627+
const link = event.target.closest('a');
628+
if (link && link.href) {
629+
window.open(link.href, '_blank');
630+
event.preventDefault();
631+
return;
632+
}
626633
}
627634
});
628635
//// 文档内容加载完毕时触发

0 commit comments

Comments
 (0)