From f97d476b495126fd2474b8e3a2968658395d2a0f Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 13 Mar 2024 17:09:48 -0400 Subject: Complete restructure --- static/assets/script.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 static/assets/script.js (limited to 'static/assets/script.js') diff --git a/static/assets/script.js b/static/assets/script.js new file mode 100644 index 0000000..a7323f3 --- /dev/null +++ b/static/assets/script.js @@ -0,0 +1,49 @@ +function stickyTopNav() { + var nav = document.querySelector('.nav'); + var header = document.querySelector('.header'); + if (document.body.scrollTop > 194 || document.documentElement.scrollTop > 194) { + if (document.querySelector('.sticky') == null) { + nav.classList.toggle('sticky'); + header.classList.toggle('sticky'); + } + } else { + if (document.querySelector('.sticky') != null) { + nav.classList.toggle('sticky'); + header.classList.toggle('sticky'); + } + } +}; + +window.onscroll = function() { + stickyTopNav(); +}; + +window.onload = function() { + stickyTopNav(); +}; + +function actionToggle() { + var action = document.querySelector('.action'); + action.classList.toggle('active') +} + +/*// https://stackoverflow.com/questions/17534661/make-anchor-link-go-some-pixels-above-where-its-linked-to + +// The function actually applying the offset +function offsetAnchor() { + if (location.hash.length !== 0) { + window.scrollTo(window.scrollX, window.scrollY - 69); + } +} + +// Captures click events of all elements with href starting with # +document.addEventListener('click', 'a[href^="#"]', function(event) { + // Click events are captured before hashchanges. Timeout + // causes offsetAnchor to be called after the page jump. + window.setTimeout(function() { + offsetAnchor(); + }, 0); +}); + +// Set the offset when entering page with hash present in the url +window.setTimeout(offsetAnchor, 0);*/ \ No newline at end of file -- cgit v1.2.3