Add scroll-to-top button to all templates

Floating button in bottom-right corner that appears when scrolling
down and smoothly scrolls to top when clicked. Each template has
matching visual style.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Miguel Astor
2026-02-26 03:09:44 -04:00
parent 9e49262118
commit 6e7f3e5e16
3 changed files with 234 additions and 0 deletions

View File

@@ -545,9 +545,73 @@
font-size: 16px;
}
}
/* Scroll to Top Button */
.scroll-top {
position: fixed;
bottom: 20px;
right: 20px;
z-index: 1000;
width: 48px;
height: 48px;
border-radius: 50%;
border: none;
background: var(--bg-primary);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
box-shadow:
6px 6px 12px var(--shadow-dark),
-6px -6px 12px var(--shadow-light);
opacity: 0;
visibility: hidden;
transition: all 0.3s ease;
}
.scroll-top.visible {
opacity: 1;
visibility: visible;
}
.scroll-top:hover {
transform: scale(1.05);
}
.scroll-top:active {
box-shadow:
inset 4px 4px 8px var(--shadow-inset-dark),
inset -4px -4px 8px var(--shadow-inset-light);
}
.scroll-top-arrow {
width: 0;
height: 0;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-bottom: 10px solid var(--text-primary);
}
@media (max-width: 600px) {
.scroll-top {
width: 40px;
height: 40px;
}
.scroll-top-arrow {
border-left-width: 6px;
border-right-width: 6px;
border-bottom-width: 8px;
}
}
</style>
</head>
<body>
<!-- Scroll to Top Button -->
<button class="scroll-top" id="scroll-top" title="Scroll to top">
<div class="scroll-top-arrow"></div>
</button>
<!-- Theme Toggle Button -->
<button class="theme-toggle" id="theme-toggle" title="Toggle theme">
<span class="icon" id="theme-icon"></span>
@@ -1106,6 +1170,27 @@
document.getElementById('tab-' + tabId).classList.add('active');
});
});
// Scroll to top button
const scrollTopBtn = document.getElementById('scroll-top');
function updateScrollTopVisibility() {
if (window.scrollY > 100) {
scrollTopBtn.classList.add('visible');
} else {
scrollTopBtn.classList.remove('visible');
}
}
window.addEventListener('scroll', updateScrollTopVisibility);
updateScrollTopVisibility();
scrollTopBtn.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
</script>
</body>
</html>