Skip to content

Commit

Permalink
trying...
Browse files Browse the repository at this point in the history
  • Loading branch information
Wulian233 committed Jan 22, 2025
1 parent 926bd9d commit 438dccc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions python_docs_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ <h3>{{ _('Navigation') }}</h3>
<script type="text/javascript" src="{{ pathto('_static/copybutton.js', 1) }}"></script>
<script type="text/javascript" src="{{ pathto('_static/menu.js', 1) }}"></script>
<script type="text/javascript" src="{{ pathto('_static/search-focus.js', 1) }}"></script>
<script type="text/javascript" src="{{ pathto('_static/smooth.js', 1) }}"></script>
<script type="text/javascript" src="{{ pathto('_static/themetoggle.js', 1) }}"></script>
{%- endif -%}
{%- endif -%}
Expand Down
9 changes: 0 additions & 9 deletions python_docs_theme/static/pydoctheme.css
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
15 changes: 15 additions & 0 deletions python_docs_theme/static/smooth.js
Original file line number Diff line number Diff line change
@@ -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';
});
});
});

0 comments on commit 438dccc

Please sign in to comment.