From 438dccc1d87a076ca001c6c1980db6327c53e250 Mon Sep 17 00:00:00 2001 From: Wulian233 <1055917385@qq.com> Date: Wed, 22 Jan 2025 10:21:19 +0800 Subject: [PATCH] trying... --- python_docs_theme/layout.html | 1 + python_docs_theme/static/pydoctheme.css | 9 --------- python_docs_theme/static/smooth.js | 15 +++++++++++++++ 3 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 python_docs_theme/static/smooth.js diff --git a/python_docs_theme/layout.html b/python_docs_theme/layout.html index 9762b06..c06ffd9 100644 --- a/python_docs_theme/layout.html +++ b/python_docs_theme/layout.html @@ -77,6 +77,7 @@

{{ _('Navigation') }}

+ {%- endif -%} {%- endif -%} diff --git a/python_docs_theme/static/pydoctheme.css b/python_docs_theme/static/pydoctheme.css index 1922cb3..4ef3319 100644 --- a/python_docs_theme/static/pydoctheme.css +++ b/python_docs_theme/static/pydoctheme.css @@ -1,14 +1,5 @@ @import url('classic.css'); -/* Smooth scroll */ -html { - scroll-behavior: auto; -} - -html:has(:target) { - scroll-behavior: smooth; -} - /* Common colours */ :root { --good-color: rgb(41 100 51); diff --git a/python_docs_theme/static/smooth.js b/python_docs_theme/static/smooth.js new file mode 100644 index 0000000..a897ab2 --- /dev/null +++ b/python_docs_theme/static/smooth.js @@ -0,0 +1,15 @@ +window.addEventListener('load', function() { + document.documentElement.style.scrollBehavior = 'auto'; + + const target = window.location.hash; + if (target) { + window.scrollTo(0, 0); + document.querySelector(target)?.scrollIntoView(); + } + + document.querySelectorAll('a[href^="#"]').forEach(anchor => { + anchor.addEventListener('click', function(e) { + document.documentElement.style.scrollBehavior = 'smooth'; + }); + }); +});