Slide in + no ugly onload animation on mobile

This commit is contained in:
saberzero1 2024-10-26 18:01:02 +02:00
parent 90e984e98b
commit c2e9477941
No known key found for this signature in database
GPG Key ID: 41AEE99107640F10
3 changed files with 37 additions and 25 deletions

View File

@ -88,7 +88,7 @@ export default ((userOpts?: Partial<Options>) => {
<button <button
type="button" type="button"
id="mobile-explorer" id="mobile-explorer"
class="collapsed" class="collapsed hide-until-loaded"
data-behavior={opts.folderClickBehavior} data-behavior={opts.folderClickBehavior}
data-collapsed={opts.folderDefaultState} data-collapsed={opts.folderDefaultState}
data-savestate={opts.useSavedState} data-savestate={opts.useSavedState}

View File

@ -40,18 +40,7 @@ function toggleExplorer(this: HTMLElement) {
if (document.querySelector("#mobile-explorer")) { if (document.querySelector("#mobile-explorer")) {
// Disable scrolling one the page when the explorer is opened on mobile // Disable scrolling one the page when the explorer is opened on mobile
const bodySelector = document.querySelector("#quartz-body") const bodySelector = document.querySelector("#quartz-body")
if (bodySelector) { if (bodySelector) bodySelector.classList.toggle("lock-scroll")
if (!bodySelector.classList.contains("lock-scroll")) {
bodySelector.setAttribute("scroll-position", `${window.scrollY}`)
bodySelector.classList.toggle("lock-scroll")
} else {
bodySelector.classList.toggle("lock-scroll")
window.scrollTo({
top: Number(bodySelector.getAttribute("scroll-position")),
behavior: "instant",
})
}
}
} }
} }
@ -195,6 +184,10 @@ document.addEventListener("nav", () => {
observer.observe(lastItem) observer.observe(lastItem)
} }
// Hide explorer on mobile until it is requested
const hiddenUntilDoneLoading = document.querySelector("#mobile-explorer")
hiddenUntilDoneLoading?.classList.remove("hide-until-loaded")
toggleExplorerFolders() toggleExplorerFolders()
}) })

View File

@ -1,12 +1,30 @@
@use "../../styles/variables.scss" as *; @use "../../styles/variables.scss" as *;
// Sticky top bar (stays in place when scrolling down on mobile.
@media all and ($mobile) { @media all and ($mobile) {
.page > #quartz-body .sidebar.left:has(.explorer) { .page > #quartz-body {
// Move page on mobile
& > :not(.sidebar.left:has(.explorer)) {
transform: translateX(0);
transition: transform 300ms ease-in-out;
}
&.lock-scroll > :not(.sidebar.left:has(.explorer)) {
transform: translateX(100dvw);
//width: 100%;
transition: transform 300ms ease-in-out;
}
// Sticky top bar (stays in place when scrolling down on mobile.
.sidebar.left:has(.explorer) {
box-sizing: border-box; box-sizing: border-box;
position: sticky; position: sticky;
background-color: var(--light); background-color: var(--light);
} }
// Hide until done loading
.hide-until-loaded ~ #explorer-content {
display: none;
}
}
} }
.explorer { .explorer {
@ -229,19 +247,20 @@ li:has(> .folder-outer:not(.open)) > .folder-container > svg {
position: absolute; position: absolute;
background-color: var(--light); background-color: var(--light);
max-width: 100dvw; max-width: 100dvw;
//left: -100dvw; left: -100dvw;
transform: translateX(-100dvw); //transform: translateX(0);
width: 100%; width: 100%;
transition: all 300ms ease-in-out; transition: transform 300ms ease-in-out;
overflow: hidden; overflow: hidden;
padding: 2rem 2rem 4rem; padding: 2rem;
height: calc(100dvh - 4rem); height: calc(100dvh - 4rem);
max-height: calc(100dvh - 4rem); max-height: calc(100dvh - 4rem);
margin-top: 2rem; margin-top: 2rem;
visibility: visible; visibility: hidden;
&:not(.collapsed) { &:not(.collapsed) {
transform: translateX(0); transform: translateX(100dvw);
visibility: visible;
} }
ul.overflow { ul.overflow {
@ -250,7 +269,7 @@ li:has(> .folder-outer:not(.open)) > .folder-container > svg {
} }
&.collapsed { &.collapsed {
transform: translateX(-100dvw); transform: translateX(0);
visibility: visible; visibility: visible;
} }
} }