mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-26 18:00:43 +01:00
docs: prevent aside to scroll up on page change
This commit is contained in:
16
docs/app.vue
16
docs/app.vue
@@ -3,7 +3,21 @@
|
|||||||
<Header />
|
<Header />
|
||||||
|
|
||||||
<UContainer>
|
<UContainer>
|
||||||
<NuxtPage />
|
<div class="relative grid lg:grid-cols-10 lg:gap-8">
|
||||||
|
<DocsAside class="lg:col-span-2" />
|
||||||
|
|
||||||
|
<div class="relative lg:col-span-6 pt-8 pb-16">
|
||||||
|
<DocsPageHeader />
|
||||||
|
|
||||||
|
<NuxtPage />
|
||||||
|
|
||||||
|
<hr class="border-gray-200 dark:border-gray-800 my-12">
|
||||||
|
|
||||||
|
<DocsPrevNext />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DocsToc class="lg:col-span-2 order-first lg:order-last" />
|
||||||
|
</div>
|
||||||
</UContainer>
|
</UContainer>
|
||||||
|
|
||||||
<DocsSearch />
|
<DocsSearch />
|
||||||
|
|||||||
@@ -1,48 +1,38 @@
|
|||||||
import type { RouterConfig } from '@nuxt/schema'
|
import type { RouterConfig } from '@nuxt/schema'
|
||||||
|
// https://router.vuejs.org/api/interfaces/routeroptions.html
|
||||||
|
export default <RouterConfig> {
|
||||||
|
scrollBehavior (to, _form, savedPosition) {
|
||||||
|
if (history.state.stop) { return }
|
||||||
|
|
||||||
function findHashPosition (hash): { el: any, behavior: ScrollBehavior, top: number } {
|
if (history.state.smooth) {
|
||||||
const el = document.querySelector(hash)
|
return {
|
||||||
// vue-router does not incorporate scroll-margin-top on its own.
|
el: history.state.smooth,
|
||||||
if (el) {
|
behavior: 'smooth'
|
||||||
const top = parseFloat(getComputedStyle(el).scrollMarginTop)
|
}
|
||||||
|
|
||||||
return {
|
|
||||||
el: hash,
|
|
||||||
behavior: 'smooth',
|
|
||||||
top
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://router.vuejs.org/api/#routeroptions
|
|
||||||
export default <RouterConfig>{
|
|
||||||
scrollBehavior (to, from, savedPosition) {
|
|
||||||
const nuxtApp = useNuxtApp()
|
|
||||||
|
|
||||||
// If history back
|
|
||||||
if (savedPosition) {
|
|
||||||
// Handle Suspense resolution
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
nuxtApp.hooks.hookOnce('page:finish', () => {
|
|
||||||
setTimeout(() => resolve(savedPosition), 50)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scroll to heading on click
|
|
||||||
if (to.hash) {
|
if (to.hash) {
|
||||||
return new Promise((resolve) => {
|
const el = document.querySelector(to.hash) as any
|
||||||
if (to.path === from.path) {
|
|
||||||
setTimeout(() => resolve(findHashPosition(to.hash)), 50)
|
if (!el) { return }
|
||||||
} else {
|
|
||||||
nuxtApp.hooks.hookOnce('page:finish', () => {
|
const { marginTop } = getComputedStyle(el)
|
||||||
setTimeout(() => resolve(findHashPosition(to.hash)), 50)
|
|
||||||
})
|
const marginTopValue = parseInt(marginTop)
|
||||||
}
|
|
||||||
})
|
const offset = (document.querySelector(to.hash) as any).offsetTop - marginTopValue
|
||||||
|
|
||||||
|
return {
|
||||||
|
top: offset,
|
||||||
|
behavior: 'smooth'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scroll to top of window
|
// Scroll to top of window
|
||||||
return { top: 0 }
|
if (savedPosition) {
|
||||||
|
return savedPosition
|
||||||
|
} else {
|
||||||
|
return { top: 0 }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<aside
|
<aside class="hidden pb-8 overflow-y-auto lg:block lg:self-start lg:top-16 lg:max-h-[calc(100vh-64px)] lg:sticky lg:pr-8 lg:pl-[2px]">
|
||||||
class="hidden pb-8 overflow-y-auto lg:block lg:self-start lg:top-16 lg:max-h-[calc(100vh-64px)] lg:sticky lg:pr-8 lg:pl-[2px]"
|
|
||||||
>
|
|
||||||
<div class="relative">
|
<div class="relative">
|
||||||
<div class="sticky top-0 pointer-events-none z-[1]">
|
<div class="sticky top-0 pointer-events-none z-[1]">
|
||||||
<div class="h-8 bg-white dark:bg-gray-900" />
|
<div class="h-8 bg-white dark:bg-gray-900" />
|
||||||
|
|||||||
@@ -1,19 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="relative grid lg:grid-cols-10 lg:gap-8">
|
<div class="prose prose-primary dark:prose-invert max-w-none">
|
||||||
<DocsAside class="lg:col-span-2" />
|
<slot />
|
||||||
|
|
||||||
<div class="relative lg:col-span-6 pt-8 pb-16">
|
|
||||||
<DocsPageHeader />
|
|
||||||
|
|
||||||
<div class="prose prose-primary dark:prose-invert max-w-none">
|
|
||||||
<slot />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<hr class="border-gray-200 dark:border-gray-800 my-12">
|
|
||||||
|
|
||||||
<DocsPrevNext />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<DocsToc class="lg:col-span-2 order-first lg:order-last" />
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user