blog/_includes/extensions/click-to-top.html
2022-04-05 22:51:38 +08:00

18 lines
477 B
HTML

<div id="click-to-top" class="click-to-top">
<i class="fa fa-arrow-up"></i>
</div>
<script>
(function () {
const clickToTop = document.getElementById('click-to-top');
window.addEventListener('scroll', () => {
if (window.scrollY > 100) {
clickToTop.classList.add('show')
}else {
clickToTop.classList.remove('show')
}
});
clickToTop.addEventListener('click', () => {
window.smoothScrollTo(0);
});
})();
</script>