feat: add smooth scroll-to-top button with Alpine transition
All checks were successful
Deploy Theme / deploy (push) Successful in 13s

This commit is contained in:
2026-02-20 12:14:17 +01:00
parent b0e1dad5ea
commit 78dc8cbd08
2 changed files with 23 additions and 0 deletions

View File

@@ -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}}
<main id="main-content" class="flex-grow">
{{{body}}}