Compare commits

...

2 Commits

Author SHA1 Message Date
Xin
cb09b7ce1e fix: skip scroll event if no backToTop element (#138) 2023-10-12 23:25:34 +01:00
96c6ff073f chore(i18n): update zh-cn.yaml (#136) 2023-10-11 23:22:07 +01:00
2 changed files with 16 additions and 10 deletions

View File

@ -1,18 +1,22 @@
const backToTop = document.querySelector("#backToTop");
// Back to top button
document.addEventListener("scroll", (event) => {
if (window.scrollY > 300) {
backToTop.classList.remove("opacity-0");
} else {
backToTop.classList.add("opacity-0");
document.addEventListener("DOMContentLoaded", function () {
const backToTop = document.querySelector("#backToTop");
if (backToTop) {
document.addEventListener("scroll", (e) => {
if (window.scrollY > 300) {
backToTop.classList.remove("opacity-0");
} else {
backToTop.classList.add("opacity-0");
}
});
}
});
function scrollUp() {
window.scroll({
top: 0,
left: 0,
behavior: 'smooth'
top: 0,
left: 0,
behavior: "smooth",
});
}

View File

@ -12,4 +12,6 @@ onThisPage: "此页上"
editThisPage: "在 GitHub 上编辑此页 →"
lastUpdated: "最后更新于"
backToTop: "返回顶部"
copyright: "© 2023 Hextra Project."