feat: scroll top button

This commit is contained in:
2025-11-15 11:17:27 +01:00
parent 448fe54e82
commit 2c039ff661
3 changed files with 78 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ const searchInput = document.getElementById('searchInput');
const linksContainer = document.getElementById('linksContainer');
const toastContainer = document.getElementById('toastContainer');
const archiveToggle = document.getElementById('archiveToggle');
const scrollToTopBtn = document.getElementById('scrollToTopBtn');
// State
let allLinks = [];
@@ -18,6 +19,7 @@ let showArchived = false;
document.addEventListener('DOMContentLoaded', () => {
loadLinks();
setupEventListeners();
setupScrollToTop();
});
// Event listeners
@@ -27,6 +29,26 @@ function setupEventListeners() {
archiveToggle.addEventListener('click', handleToggleArchive);
}
// Setup scroll to top button
function setupScrollToTop() {
// Show/hide button based on scroll position
window.addEventListener('scroll', () => {
if (window.pageYOffset > 300) {
scrollToTopBtn.classList.add('show');
} else {
scrollToTopBtn.classList.remove('show');
}
});
// Scroll to top when button is clicked
scrollToTopBtn.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
}
// Load all links
async function loadLinks() {
try {