blog/_includes/extensions/click-to-top.html

19 lines
477 B
HTML
Raw Normal View History

2022-04-05 16:51:38 +02:00
<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>