feat: add dynamic header hiding on scroll and back-to-top button

- Hide header when scrolling down, show when scrolling up
- Smooth transition animations for header hide/show
- Floating back-to-top button in bottom right corner
- Button appears after 300px scroll
- Circular button with arrow icon and smooth animations
- Mobile-responsive sizing for back-to-top button
- Both features excluded from print view
This commit is contained in:
juanatsap
2025-11-07 21:38:34 +00:00
parent 74c8374a7c
commit 2f09011abc
2 changed files with 115 additions and 0 deletions
+50
View File
@@ -248,6 +248,11 @@
<button onclick="this.parentElement.style.display='none'" aria-label="Close error message" class="error-close">×</button>
</div>
<!-- Back to Top Button -->
<button id="back-to-top" class="back-to-top no-print" aria-label="{{if eq .Lang "es"}}Volver arriba{{else}}Back to top{{end}}" style="display: none;">
<iconify-icon icon="mdi:arrow-up" width="24" height="24"></iconify-icon>
</button>
<script>
// Toggle navigation menu
function toggleMenu() {
@@ -395,6 +400,51 @@
}
});
// Scroll Direction Detection - Hide/Show Header
let lastScrollTop = 0;
let scrollThreshold = 100; // Start hiding after 100px scroll
window.addEventListener('scroll', function() {
const actionBar = document.querySelector('.action-bar');
const navMenu = document.querySelector('.navigation-menu');
const backToTopBtn = document.getElementById('back-to-top');
const currentScroll = window.pageYOffset || document.documentElement.scrollTop;
// Hide/show header based on scroll direction
if (currentScroll > scrollThreshold) {
if (currentScroll > lastScrollTop) {
// Scrolling down - hide header
actionBar.classList.add('header-hidden');
navMenu.classList.add('header-hidden');
} else {
// Scrolling up - show header
actionBar.classList.remove('header-hidden');
navMenu.classList.remove('header-hidden');
}
} else {
// At top - always show header
actionBar.classList.remove('header-hidden');
navMenu.classList.remove('header-hidden');
}
// Show/hide back to top button
if (currentScroll > 300) {
backToTopBtn.style.display = 'flex';
} else {
backToTopBtn.style.display = 'none';
}
lastScrollTop = currentScroll <= 0 ? 0 : currentScroll;
}, false);
// Back to top button click handler
document.getElementById('back-to-top').addEventListener('click', function() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
// Error handling utility
function showError(message) {
const errorToast = document.getElementById('error-toast');