feat: add button scroll to top

main
Yuri Dimas 2025-12-02 00:48:17 +07:00
parent 26eb2f1cef
commit 5a7d5cc85c
No known key found for this signature in database
GPG Key ID: 9FD7E44BC294C68C
1 changed files with 30 additions and 2 deletions

View File

@ -672,6 +672,14 @@
</div>
</section>
<!-- Scroll to top FAB -->
<div class="fixed right-4 bottom-6 md:right-10 md:bottom-10 z-50">
<button type="button" id="scrollTopFab"
class="btn btn-success btn-circle text-white shadow-xl hidden" aria-label="Kembali ke atas">
<i class="ph ph-arrow-up text-xl"></i>
</button>
</div>
@section Styles {
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
}
@ -863,7 +871,7 @@
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver(function(entries) {
const observer = new IntersectionObserver(function (entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-fade-in');
@ -896,5 +904,25 @@
});
});
})();
// Scroll-to-top floating action button
(function () {
const scrollFab = document.getElementById('scrollTopFab');
if (!scrollFab) return;
const toggleVisibility = () => {
scrollFab.classList.toggle('hidden', window.scrollY < 300);
};
toggleVisibility();
window.addEventListener('scroll', toggleVisibility);
scrollFab.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
})();
</script>
}
}