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

ENH animation for the top banner #1693

Merged
merged 6 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 13 additions & 9 deletions src/pydata_sphinx_theme/assets/scripts/pydata-sphinx-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,22 +517,26 @@ function showVersionWarningBanner(data) {
inner.appendChild(button);
const skipLink = document.getElementById("pst-skip-link");
skipLink.after(outer);
const autoHeight = outer.offsetHeight;

// At least 3rem height
const autoHeight = Math.min(
outer.offsetHeight,
3 * parseFloat(getComputedStyle(document.documentElement).fontSize)
);
// Set height and vertical padding to 0 to prepare the height transition
outer.style.height = 0;
outer.style.paddingTop = 0;
outer.style.paddingBottom = 0;
outer.style.setProperty("height", 0);
outer.style.setProperty("padding-top", 0);
outer.style.setProperty("padding-bottom", 0);
outer.classList.remove("init");
// Set height to the computed height with a small timeout to activate the transition
setTimeout(() => {
outer.style.height = `${autoHeight}px`;
outer.style.setProperty("height", `${autoHeight}px`);
// Wait for a bit more than 300ms (the transition duration) then remove the
// forcefully set styles and let CSS take over
setTimeout(() => {
outer.style.paddingTop = "";
outer.style.paddingBottom = "";
outer.style.height = "";
outer.style.removeProperty("padding-top");
outer.style.removeProperty("padding-bottom");
outer.style.removeProperty("height");
outer.style.setProperty("min-height", "3rem");
}, 320);
}, 10);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,25 @@
div = document.querySelector(".bd-header-announcement");
div.classList.add(...{{ header_classes | tojson }});
div.innerHTML = `<div class="bd-header-announcement__content">${data}</div>`;
const autoHeight = div.offsetHeight;
// At least 3rem height
const autoHeight = Math.min(
div.offsetHeight,
3 * parseFloat(getComputedStyle(document.documentElement).fontSize));
// Set height and vertical padding to 0 to prepare the height transition
div.style.height = 0;
div.style.paddingTop = 0;
div.style.paddingBottom = 0;
div.style.setProperty("height", 0);
div.style.setProperty("padding-top", 0);
div.style.setProperty("padding-bottom", 0);
div.classList.remove("init");
// Set height to the computed height with a small timeout to activate the transition
setTimeout(() => {
div.style.height = `${autoHeight}px`;
div.style.setProperty("height", `${autoHeight}px`);
// Wait for a bit more than 300ms (the transition duration) then remove the
// forcefully set styles and let CSS take over
setTimeout(() => {
div.style.paddingTop = "";
div.style.paddingBottom = "";
div.style.height = "";
div.style.removeProperty("padding-top");
div.style.removeProperty("padding-bottom");
div.style.removeProperty("height");
div.style.setProperty("min-height", "3rem");
}, 320);
}, 10);
})
Expand Down
Loading