From a486b9025e0c27d5e5132e23c14c450065d7b9e9 Mon Sep 17 00:00:00 2001 From: DaleStack <211448639+DaleStack@users.noreply.github.com> Date: Fri, 1 Aug 2025 02:32:49 +0800 Subject: [PATCH] docs: added scroll-to-top button with JS and CSS --- docs/_static/scrolltop.css | 15 +++++++++++++++ docs/_static/scrolltop.js | 17 +++++++++++++++++ docs/conf.py | 4 ++++ 3 files changed, 36 insertions(+) create mode 100644 docs/_static/scrolltop.css create mode 100644 docs/_static/scrolltop.js diff --git a/docs/_static/scrolltop.css b/docs/_static/scrolltop.css new file mode 100644 index 00000000..12a668ca --- /dev/null +++ b/docs/_static/scrolltop.css @@ -0,0 +1,15 @@ +#scrollToTop { + position: fixed; + top: 20px; + right: 20px; + background-color: #5EABD6; + color: white; + border: none; + padding: 10px 15px; + border-radius: 5px; + font-size: 14px; + cursor: pointer; + z-index: 1000; + display: none; + box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2); +} diff --git a/docs/_static/scrolltop.js b/docs/_static/scrolltop.js new file mode 100644 index 00000000..7f0d8281 --- /dev/null +++ b/docs/_static/scrolltop.js @@ -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); +}); diff --git a/docs/conf.py b/docs/conf.py index af8adf01..4669b34d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -62,6 +62,10 @@ html_favicon = "_static/flask-icon.svg" html_logo = "_static/flask-logo.svg" html_title = f"Flask Documentation ({version})" html_show_sourcelink = False +html_static_path = ['_static'] +html_js_files = ['scrolltop.js'] +html_css_files = ['scrolltop.css'] + gettext_uuid = True gettext_compact = False