diff options
author | 裸奔狂甩丁丁 <30397306+StreakingMan@users.noreply.github.com> | 2022-04-05 22:51:38 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-05 22:51:38 +0800 |
commit | ffb0e94ff53d3585efd7acad7560dd11a153f5e6 (patch) | |
tree | f537f5827810c902830da5cc33255abaa47d792a /_includes | |
parent | ad83aa4302f035ab2f76f2f239e8748fa3e9f0c7 (diff) |
feat: click to top (#84)
Diffstat (limited to '_includes')
-rw-r--r-- | _includes/extensions/click-to-top.html | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/_includes/extensions/click-to-top.html b/_includes/extensions/click-to-top.html new file mode 100644 index 0000000..fadd325 --- /dev/null +++ b/_includes/extensions/click-to-top.html @@ -0,0 +1,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> |