Browse Source

fix(layouts): restore smooth scrolling to toc links

Josh Habdas 1 year ago
parent
commit
89a9c8d412
Signed by: Josh Habdas <jhabdas@protonmail.com> GPG Key ID: B148B31154C75A74
1 changed files with 5 additions and 2 deletions
  1. 5
    2
      layouts/partials/toc-maybe.html

+ 5
- 2
layouts/partials/toc-maybe.html View File

@@ -11,10 +11,13 @@
11 11
         el.onclick = null;
12 12
       };
13 13
       document.querySelectorAll('#TableOfContents a').forEach(link => {
14
-        link.addEventListener('click', () => {
14
+        link.addEventListener('click', (evt) => {
15
+          evt.preventDefault();
16
+          const selector = link.href.slice(link.href.indexOf('#'));
15 17
           document.querySelector(
16
-            link.href.slice(link.href.indexOf('#'))
18
+            selector
17 19
           ).scrollIntoView({ behavior: 'smooth' });
20
+          window.history.pushState({}, "", selector);
18 21
         });
19 22
       });
20 23
     })(window, document);

Loading…
Cancel
Save