Scroll Animation
Scroll To
ScrollTo.vue<script setup lang="ts">
import { ScrollTo, SmoothScroll } from 'beui-vue'
import { useId } from 'vue'
// ScrollTo uses the active SmoothScroll provider. Here it is contained (:root="false"); the nav buttons glide the box to each section.
const prefix = useId()
const sections = ['Intro', 'Features', 'Pricing', 'FAQ']
</script>
<template>
<SmoothScroll :root="false" class="scroll-frame" role="region" aria-label="Scroll to section" tabindex="0">
<nav class="nav" aria-label="Sections">
<ScrollTo v-for="section in sections" :key="section" :to="`#${prefix}-${section}`" :offset="-48" class="link">{{ section }}</ScrollTo>
</nav>
<section v-for="section in sections" :id="`${prefix}-${section}`" :key="section" :data-pricing="section === 'Pricing' ? '' : undefined" class="section">{{ section }}</section>
</SmoothScroll>
</template>
<style scoped>
.scroll-frame { box-sizing: border-box; position: relative; width: 100%; max-width: 32rem; height: 20rem; overflow-y: auto; scrollbar-width: none; border: 1px solid var(--beui-border); border-radius: 1rem; background: var(--beui-card); }
.scroll-frame::-webkit-scrollbar { display: none; }
.nav { position: sticky; top: 0; z-index: 10; display: flex; gap: .375rem; padding: .5rem; border-bottom: 1px solid var(--beui-border); background: color-mix(in srgb, var(--beui-background) 80%, transparent); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.link { padding: .25rem .75rem; border: 0; border-radius: 999px; background: transparent; font: inherit; font-size: .875rem; line-height: 1.25rem; color: var(--beui-muted-foreground); cursor: pointer; transition: background-color .15s, color .15s; }
.link:hover { background: var(--beui-muted); color: var(--beui-foreground); }
.section { display: flex; height: 16rem; align-items: center; justify-content: center; font-size: 1.125rem; line-height: 1.75rem; font-weight: 500; color: var(--beui-foreground); }
</style><script setup lang="ts">
import { animate } from 'motion-v'
import { useReducedMotion } from '../core/reduced-motion'
import { onBeforeUnmount } from 'vue'
import { useSmoothScrollProvider } from '../layout/scroll-context'
const { to, offset = 0, duration, container } = defineProps<{ to: number | string | HTMLElement; offset?: number; duration?: number; container?: HTMLElement | null }>()
const reduce = useReducedMotion()
const provider = useSmoothScrollProvider()
let cancel: (() => void) | undefined
function navigate() {
cancel?.()
if (provider && !container) { provider.scrollTo(to, { offset, duration, immediate: duration === 0 }); return }
const host = container ?? window
const origin = container?.scrollTop ?? window.scrollY
let target: number
if (typeof to === 'number') target = to
else {
let element: Element | null
if (typeof to === 'string') {
try { element = (container ?? document).querySelector(to) } catch { return }
} else element = to
if (!element) return
const containerTop = container ? container.getBoundingClientRect().top + container.clientTop : 0
target = element.getBoundingClientRect().top - containerTop + origin
}
const top = target + offset
if (!duration || duration <= 0 || reduce.value) {
host.scrollTo({ top, behavior: reduce.value || duration === 0 ? 'instant' : 'smooth' })
return
}
const motion = animate(origin, top, {
duration, ease: time => Math.min(1, 1.001 - 2 ** (-10 * time)),
onUpdate: next => host.scrollTo({ top: next, behavior: 'instant' }),
onComplete: () => stop(),
})
function stop() {
motion.stop()
host.removeEventListener('wheel', stop)
host.removeEventListener('touchstart', stop)
cancel = undefined
}
host.addEventListener('wheel', stop, { passive: true })
host.addEventListener('touchstart', stop, { passive: true })
cancel = stop
}
onBeforeUnmount(() => cancel?.())
</script>
<template><button type="button" @click="navigate"><slot /></button></template>Install
Run it in a project set up with shadcn-vue. The source is copied to components/beui and its dependencies are added to your package.json. Read the shadcn-vue guide
$ bunx --bun shadcn-vue@latest add @beui-vue/scroll-to$ bun add beui-vueDownload the release archive to your project root, then install the local file.
$ bun add ./beui-vue-0.1.0.tgzImport the shared styles once in your application.
import ScrollTo from '@/components/beui/effects/ScrollTo.vue'
import '@/components/beui/styles.css'API Reference
tonumber | string | HTMLElementWhere to scroll: px offset, selector string or element.
—offset?numberExtra px offset from the target (e.g. to clear a sticky header).
0duration?numberOverride the ease duration in seconds.
—class?string—container?HTMLElement | null—Related components
Tabs
Pill, segment or underline tabs with a spring layoutId indicator and optional icons.
Shared Layout Background
A pill that glides between hovered items via motion's shared layout, with blur enter/exit.
Preview Rail
Codex app-inspired navigation rail with compact ticks that form a hover pyramid and reveal a floating destination preview.
Updated