Skip to content

Commit 230cbaa

Browse files
committed
feat: improve code page scroll to top
1 parent 85ac3d7 commit 230cbaa

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

app/pages/package-code/[[org]]/[packageName]/v/[version]/[...filePath].vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ function scrollToTop() {
256256
contentContainer.value.scrollTo({ top: 0, behavior: 'smooth' })
257257
}
258258
}
259+
const { y } = useScroll(contentContainer)
260+
const isVisible = computed(() => {
261+
return y.value > SCROLL_TO_TOP_THRESHOLD
262+
})
259263
260264
// Canonical URL for this code page
261265
const canonicalUrl = computed(() => `https://npmx.dev${getCodeUrl(route.params)}`)
@@ -459,6 +463,7 @@ defineOgImageComponent('Default', {
459463
</div>
460464
<div class="flex items-center gap-2">
461465
<button
466+
v-if="isVisible"
462467
type="button"
463468
class="px-2 py-1 font-mono text-xs text-fg-muted bg-bg-subtle border border-border rounded hover:text-fg hover:border-border-hover transition-colors items-center inline-flex gap-1"
464469
@click="scrollToTop"

0 commit comments

Comments
 (0)