Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add animations to the sidebar and other small places #210

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 30 additions & 0 deletions python_docs_theme/static/pydoctheme.css
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ form.inline-search input[type='submit'] {
}

div.document {
animation: fadeIn 0.6s ease-in-out;
Wulian233 marked this conversation as resolved.
Show resolved Hide resolved
display: flex;
/* Don't let long code literals extend beyond the right side of the screen */
overflow-wrap: break-word;
Expand All @@ -149,6 +150,7 @@ div.sphinxsidebar {
border-radius: 5px;
line-height: 130%;
font-size: smaller;
transition: width 0.3s ease;
}

div.sphinxsidebar h3,
Expand Down Expand Up @@ -205,6 +207,9 @@ div.sphinxsidebar input[type='text'] {
width: 12px;
border-radius: 0 5px 5px 0;
border-left: none;
position: absolute;
right: 0;
transition: background-color 0.3s ease, color 0.3s ease;
}

#sidebarbutton span {
Expand Down Expand Up @@ -761,3 +766,28 @@ div.versionremoved .versionmodified {
display: none;
}
}

/* Animation */
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}

@media (prefers-reduced-motion) {
div.document {
animation: none;
transition: none;
}

#sidebarbutton {
transition: none;
}

html {
scroll-behavior: auto;
}
}
15 changes: 15 additions & 0 deletions python_docs_theme/static/smooth.js
Wulian233 marked this conversation as resolved.
Show resolved Hide resolved
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';
});
});
});
Loading