瀏覽代碼

Menu items now open when you scroll down in the default theme.

Bart Hijmans 2 年之前
父節點
當前提交
d2c119ead9
共有 1 個文件被更改,包括 13 次插入0 次删除
  1. 13 0
      resources/js/theme-default.js

+ 13 - 0
resources/js/theme-default.js

@@ -132,5 +132,18 @@ document.addEventListener('DOMContentLoaded', function() {
 
     window.addEventListener('hashchange', hashChange, false);
 
+    const divs = document.querySelectorAll('.content h1[id], .content h2[id]');
+
+    document.addEventListener('scroll', () => {
+        divs.forEach(item => {
+            const rect = item.getBoundingClientRect();
+            if (rect.top > 0 && rect.top < 150) {
+                const location = window.location.toString().split('#')[0];
+                history.replaceState(null, null, location + '#' + item.id);
+                hashChange();
+            }
+        });
+    });
+
     hashChange();
 });