diff --git a/default.hbs b/default.hbs index 803e8f9..1bef72b 100644 --- a/default.hbs +++ b/default.hbs @@ -4,6 +4,7 @@ theme: localStorage.getItem('theme') || (window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'), mobileMenuOpen: false, currentPath: window.location.pathname, + showScrollTop: false, init() { $watch('theme', val => { localStorage.setItem('theme', val); @@ -12,6 +13,11 @@ document.documentElement.setAttribute('data-theme', this.theme); document.documentElement.classList.remove('hidden'); + // Handle scroll for scroll-to-top button + window.addEventListener('scroll', () => { + this.showScrollTop = window.scrollY > 400; + }); + // Update currentPath on navigation to keep menu highlights in sync document.addEventListener('htmx:afterSettle', () => { this.currentPath = window.location.pathname; @@ -49,6 +55,7 @@ --}} {{> mobile-menu}} {{> header}} + {{> scroll-top}}
{{{body}}} diff --git a/partials/scroll-top.hbs b/partials/scroll-top.hbs new file mode 100644 index 0000000..f57774e --- /dev/null +++ b/partials/scroll-top.hbs @@ -0,0 +1,16 @@ +