Skip to content

Commit

Permalink
2021-05-09 17:19:25
Browse files Browse the repository at this point in the history
  • Loading branch information
wizardforcel committed May 9, 2021
1 parent 0442e03 commit 619124b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
19 changes: 19 additions & 0 deletions asset/back-to-top.css
Original file line number Diff line number Diff line change
@@ -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;
}
20 changes: 20 additions & 0 deletions asset/back-to-top.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
10 changes: 10 additions & 0 deletions asset/up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<script src="asset/share.js"></script>
<link rel="stylesheet" href="asset/edit.css">
<script src="asset/edit.js"></script>
<link rel="stylesheet" href="asset/back-to-top.css">
<script src="asset/back-to-top.js"></script>
</head>
<body>
<div id="app">now loading...</div>
Expand Down

0 comments on commit 619124b

Please sign in to comment.