docs: added scroll-to-top button with JS and CSS

This commit is contained in:
DaleStack 2025-08-01 02:32:49 +08:00
parent 85cc710464
commit a486b9025e
3 changed files with 36 additions and 0 deletions

17
docs/_static/scrolltop.js vendored Normal file
View file

@ -0,0 +1,17 @@
window.addEventListener("scroll", function () {
const btn = document.getElementById("scrollToTop");
btn.style.display = window.scrollY > 300 ? "block" : "none";
});
function scrollToTop() {
window.scrollTo({ top: 0, behavior: "smooth" });
}
document.addEventListener("DOMContentLoaded", () => {
const btn = document.createElement("button");
btn.id = "scrollToTop";
btn.textContent = "↑ Top";
btn.setAttribute("aria-label", "Scroll to top");
btn.onclick = scrollToTop;
document.body.appendChild(btn);
});