From 2a834118bbc72dbf1f4221b4b73a091c0b6271e7 Mon Sep 17 00:00:00 2001 From: wizardforcel <562826179@qq.com> Date: Sun, 9 May 2021 17:22:23 +0800 Subject: [PATCH] 2021-05-09 17:22:23 --- asset/back-to-top.css | 19 +++++++++++++++++++ asset/back-to-top.js | 20 ++++++++++++++++++++ asset/up.svg | 10 ++++++++++ index.html | 2 ++ 4 files changed, 51 insertions(+) create mode 100644 asset/back-to-top.css create mode 100644 asset/back-to-top.js create mode 100644 asset/up.svg diff --git a/asset/back-to-top.css b/asset/back-to-top.css new file mode 100644 index 0000000..bcb3d5a --- /dev/null +++ b/asset/back-to-top.css @@ -0,0 +1,19 @@ +#scroll-btn { + position: fixed; + right: 15px; + bottom: 10px; + width: 35px; + height: 35px; + background-repeat: no-repeat; + background-size: cover; + cursor: pointer; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + background-image: url(up.svg); + background-position-y: -1px; + display: none; + border: 2px solid; + border-radius: 4px; +} \ No newline at end of file diff --git a/asset/back-to-top.js b/asset/back-to-top.js new file mode 100644 index 0000000..3efad9b --- /dev/null +++ b/asset/back-to-top.js @@ -0,0 +1,20 @@ +document.addEventListener('DOMContentLoaded', function() { + var scrollBtn = document.createElement('div') + scrollBtn.id = 'scroll-btn' + document.body.append(scrollBtn) + + window.addEventListener('scroll', function() { + var offset = window.document.documentElement.scrollTop; + scrollBtn.style.display = offset >= 500 ? "block" : "none"; + }) + scrollBtn.addEventListener('click', function(e) { + e.stopPropagation(); + var step = window.scrollY / 15; + var hdl = setInterval(function() { + window.scrollTo(0, window.scrollY - step); + if(window.scrollY <= 0) { + clearInterval(hdl) + } + }, 15) + }) +}) \ No newline at end of file diff --git a/asset/up.svg b/asset/up.svg new file mode 100644 index 0000000..ee90b8f --- /dev/null +++ b/asset/up.svg @@ -0,0 +1,10 @@ + + + + 1211 + + + + + + \ No newline at end of file diff --git a/index.html b/index.html index 43e729f..1efc902 100644 --- a/index.html +++ b/index.html @@ -22,6 +22,8 @@ + +
now loading...
-- GitLab