web/_javascript/modules/components/back-to-top.js
Cotes Chung fe7afa379f
perf: replace jQuery with Vanilla JS (#1681)
Also replaced `magnific-popup` with `GLightbox`
2024-04-17 06:10:01 +08:00

19 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 });
});
}