Kaynağa Gözat

【新增】优化导航按钮点击事件并添加外部链接打开优化

- 更新了导航按钮的 CSS 选择器,提高选择精度
- 添加了对内容区域外部链接的点击事件处理,实现新窗口打开
- 优化了平滑滚动的逻辑,修复了特定情况下的滚动问题
PJ568 1 yıl önce
ebeveyn
işleme
abb98b137b
1 değiştirilmiş dosya ile 13 ekleme ve 6 silme
  1. 13 6
      index.html

+ 13 - 6
index.html

@@ -1,7 +1,7 @@
 <!doctype html>
 
 <html>
-<markdown-html version="1.13.1" author="PJ568" repo="https://github.com/PJ-568/markdown.html"
+<markdown-html version="1.14.0" author="PJ568" repo="https://github.com/PJ-568/markdown.html"
   license="CC BY-SA 4.0 International"></markdown-html>
 
 <head>
@@ -601,15 +601,15 @@
             return;
           }
         }
-        if (event.target.closest('.back-btn')) {
+        if (event.target.closest('nav .back-btn')) {
           window.history.back();
-        } else if (event.target.closest('.refresh-btn')) {
+        } else if (event.target.closest('nav .refresh-btn')) {
           window.location.reload();
-        } else if (event.target.closest('.dark-btn')) {
+        } else if (event.target.closest('nav .dark-btn')) {
           darkmode.toggle();
-        } else if (event.target.closest('.translate-switch')) {
+        } else if (event.target.closest('nav .translate-switch')) {
           translate.changeLanguage(translate.language.getLocal());
-        } else if (event.target.closest('a[href^="#"]')) {
+        } else if (event.target.closest('.content a[href^="#"]')) {
           // 目录平滑移动
           const href = event.target.getAttribute('href');
           if (href !== '#') {
@@ -623,6 +623,13 @@
               console.error(`ID 为 ${targetId} 的元素不存在。`);
             }
           }
+        } else if (event.target.closest('.content a:not([href$=".md"])')) {
+          const link = event.target.closest('a');
+          if (link && link.href) {
+            window.open(link.href, '_blank');
+            event.preventDefault();
+            return;
+          }
         }
       });
       //// 文档内容加载完毕时触发