Browse Source

feat(docs): Scroll active nav menu item into view

Michael Bromley 5 năm trước cách đây
mục cha
commit
6fbe1db9d7
1 tập tin đã thay đổi với 5 bổ sung0 xóa
  1. 5 0
      docs/assets/scripts/nav-menu.ts

+ 5 - 0
docs/assets/scripts/nav-menu.ts

@@ -1,6 +1,11 @@
 export function initNavMenu() {
     const sections = document.querySelectorAll('nav li.section');
     sections.forEach(makeExpandable);
+
+    const activeLink = document.querySelector('nav a.active');
+    if (activeLink) {
+        activeLink.scrollIntoView({ block: 'center' });
+    }
 }
 
 function makeExpandable(section: Element) {