diff --git a/asset/back-to-top.css b/asset/back-to-top.css new file mode 100644 index 0000000000000000000000000000000000000000..bcb3d5a7579e4b25df8e05f461f8ff3ae21631f9 --- /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 0000000000000000000000000000000000000000..3efad9be05b26f9da577e70bfe40796b8ab80d5a --- /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 0000000000000000000000000000000000000000..ee90b8fec92422491f1b70c131a82d8bab20419d --- /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 43e729fe0bf12bca4edd2fbbc9c8106c9c227c6b..1efc9027df3fd2657dbc43556622cd7ebb99c64c 100644 --- a/index.html +++ b/index.html @@ -22,6 +22,8 @@ + +
now loading...