docs: added scroll-to-top button with JS and CSS
This commit is contained in:
parent
85cc710464
commit
a486b9025e
3 changed files with 36 additions and 0 deletions
17
docs/_static/scrolltop.js
vendored
Normal file
17
docs/_static/scrolltop.js
vendored
Normal 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);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue