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) => { document.addEventListener("DOMContentLoaded", function () {
if (window.scrollY > 300) { const backToTop = document.querySelector("#backToTop");
backToTop.classList.remove("opacity-0"); if (backToTop) {
} else { document.addEventListener("scroll", (e) => {
backToTop.classList.add("opacity-0"); if (window.scrollY > 300) {
backToTop.classList.remove("opacity-0");
} else {
backToTop.classList.add("opacity-0");
}
});
} }
}); });
function scrollUp() { function scrollUp() {
window.scroll({ window.scroll({
top: 0, top: 0,
left: 0, left: 0,
behavior: 'smooth' behavior: "smooth",
}); });
} }

View File

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