-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite.js
35 lines (28 loc) · 952 Bytes
/
site.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(function () {
const buttonUpEl = document.getElementById("btn-up");
document.addEventListener("DOMContentLoaded", function (e) {
const copyrightEl = document.getElementById("copyright");
const copyrightText = copyrightEl.innerHTML;
const currentYear = new Date().getFullYear();
copyrightEl.innerHTML = copyrightText.replace("[year]", currentYear);
});
window.addEventListener("scroll", function (e) {
const { clientHeight } = document.documentElement;
const { pageYOffset } = window;
if (pageYOffset > clientHeight) {
buttonUpEl.classList.add("show");
} else {
buttonUpEl.classList.remove("show");
}
});
function scrollUp() {
const scrollStep = window.pageYOffset / 20;
if (scrollStep < 0.1) {
window.scrollTo(0, 0);
return;
}
window.scrollBy(0, -scrollStep)
setTimeout(() => scrollUp(), 10);
}
buttonUpEl.addEventListener("click", scrollUp);
}());