chirpy/_javascript/modules/components/back-to-top.js
yann 8f0a4fe910
Some checks are pending
Build and Deploy / build (push) Waiting to run
Build and Deploy / deploy (push) Blocked by required conditions
first commit
2025-04-15 16:46:12 +02:00

20 lines
415 B
JavaScript

/**
* Reference: https://bootsnipp.com/snippets/featured/link-to-top-page
*/
export function back2top() {
const btn = document.getElementById('back-to-top');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
btn.classList.add('show');
} else {
btn.classList.remove('show');
}
});
btn.addEventListener('click', () => {
window.scrollTo({ top: 0 });
});
}