summaryrefslogtreecommitdiff
path: root/_includes/extensions/click-to-top.html
blob: fadd32501a9a5f73fd96f06bf76a2536d44e49f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<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>