summaryrefslogtreecommitdiff
path: root/docs/public/nav.js
diff options
context:
space:
mode:
authorGravatar Fred K. Schott <fkschott@gmail.com> 2021-07-16 12:57:07 -0400
committerGravatar GitHub <noreply@github.com> 2021-07-16 11:57:07 -0500
commit2827f077baab6674a8ee47f3006e82ce991118b8 (patch)
tree6ec6bbf3fc38a481816c6ed471f52bda39393a6d /docs/public/nav.js
parent6d06fce6d2f47ee793b98b970212b27e8dc059f2 (diff)
downloadastro-2827f077baab6674a8ee47f3006e82ce991118b8.tar.gz
astro-2827f077baab6674a8ee47f3006e82ce991118b8.tar.zst
astro-2827f077baab6674a8ee47f3006e82ce991118b8.zip
New getting started guide (#715)
* New getting started guide * style: small style tweaks * style: theme updates * chore: add redirect * style: theme tweaks * fix: clamp logo height * style: fix sidebar width Co-authored-by: Nate Moore <nate@skypack.dev>
Diffstat (limited to 'docs/public/nav.js')
-rw-r--r--docs/public/nav.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/docs/public/nav.js b/docs/public/nav.js
new file mode 100644
index 000000000..93fadcd61
--- /dev/null
+++ b/docs/public/nav.js
@@ -0,0 +1,37 @@
+const nav = document.querySelector('body > header');
+
+if (!window.matchMedia('(prefers-reduced-motion)').matches) {
+ window.addEventListener('scroll', onScroll, { passive: true });
+}
+
+let prev = -1;
+let prevDir = 0;
+let threshold = 32;
+
+function onScroll() {
+ const curr = window.scrollY;
+ const dir = curr > prev ? 1 : -1;
+
+ if (curr < threshold) {
+ show();
+ document.documentElement.classList.add('initial');
+ } else if (dir !== prevDir) {
+ if (dir === 1) {
+ hide();
+ } else {
+ show();
+ }
+ }
+
+ prev = curr;
+}
+
+const hide = () => {
+ nav.classList.add('hidden')
+ document.documentElement.classList.add('scrolled');
+ document.documentElement.classList.remove('initial');
+};
+const show = () => {
+ nav.classList.remove('hidden');
+ document.documentElement.classList.remove('scrolled');
+}