소스 검색

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

Michael Bromley 5 년 전
부모
커밋
6fbe1db9d7
1개의 변경된 파일5개의 추가작업 그리고 0개의 파일을 삭제
  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) {