Просмотр исходного кода

Account for the header when hash-scrolling

Saria Hajjar 6 лет назад
Родитель
Сommit
2f2e193cf9
1 измененных файлов с 15 добавлено и 0 удалено
  1. 15 0
      netbox/project-static/js/forms.js

+ 15 - 0
netbox/project-static/js/forms.js

@@ -353,4 +353,19 @@ $(document).ready(function() {
         });
         });
         $('select#id_mode').trigger('change');
         $('select#id_mode').trigger('change');
     }
     }
+
+    // Scroll up an offset equal to the first nav element if a hash is present
+    // Cannot use '#navbar' because it is not always visible, like in small windows
+    function headerOffsetScroll() {
+        if (window.location.hash) {
+            // Short wait needed to allow the page to scroll to the element
+            setTimeout(function() {
+                window.scrollBy(0, -$('nav').height())
+            }, 10);
+        }
+    }
+
+    // Account for the header height when hash-scrolling
+    window.addEventListener('load', headerOffsetScroll);
+    window.addEventListener('hashchange', headerOffsetScroll);
 });
 });