feat: add smooth scroll-to-top button with Alpine transition
All checks were successful
Deploy Theme / deploy (push) Successful in 13s
All checks were successful
Deploy Theme / deploy (push) Successful in 13s
This commit is contained in:
@@ -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}}}
|
||||
|
||||
Reference in New Issue
Block a user