浏览代码

Merge pull request #377 from james2doyle/missing-headings

Fixed: reduce margins and only pay attention to menu anchors
Shalvah 3 年之前
父节点
当前提交
028d6064a5
共有 1 个文件被更改,包括 8 次插入3 次删除
  1. 8 3
      resources/js/theme-default.js

+ 8 - 3
resources/js/theme-default.js

@@ -14,7 +14,7 @@ document.addEventListener('DOMContentLoaded', function() {
 
         throttledUpdateHash(entries[0].target.id);
     }, {
-        rootMargin: '-8% 0px -8% 0px', // shrink the intersection viewport
+        rootMargin: '0px 0px -12% 0px', // shrink the intersection viewport
         threshold: 1.0, // trigger at 100% visibility
     });
 
@@ -22,8 +22,13 @@ document.addEventListener('DOMContentLoaded', function() {
         return observer.observe(elem);
     }
 
-    const titles = document.querySelectorAll('.content h1, .content h2');
-    Array.from(titles).forEach(makeObserver);
+    // find all links in the menu
+    const menuItems = document.querySelectorAll('#toc a[href]');
+    // make observers for those links
+    Array.from(menuItems).forEach((aTag) => {
+        const title = document.querySelector(aTag.getAttribute('href'));
+        makeObserver(title);
+    });
 
     const navButton = document.getElementById('nav-button');
     const menuWrapper = document.querySelector('.tocify-wrapper');