Quellcode durchsuchen

Fixed: reduce margins and only pay attention to menu anchors

James Doyle vor 3 Jahren
Ursprung
Commit
3e021981e7
1 geänderte Dateien mit 8 neuen und 3 gelöschten Zeilen
  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');