Back to Vuetify

Programmatic scrolling

packages/docs/src/pages/en/features/scrolling.md

4.0.61.1 KB
Original Source

Programmatic scrolling

Handle scrolling within your application by using the goTo function.

<PageFeatures /> <PromotedEntry />

Usage

The goTo method takes two parameters target and options. target can be either a pixel offset from the top of the page, a valid css selector, or an element reference. options is an object that includes duration, easing, container, and offset.

<ExamplesExample file="scroll/usage" />

API

DirectiveDescription
useGoToThe useGoTo composable
<ApiInline hide-links /> <!--## Use with router The **goTo** function can be individually imported and invoked anywhere. This is particularly useful when hooking up to [vue-router](https://router.vuejs.org/). ```js { resource="src/router.js" } import Router from 'vue-router' import goTo from 'vuetify/lib/services/goto' export default new Router({ scrollBehavior: (to, from, savedPosition) => { let scrollTo = 0 if (to.hash) { scrollTo = to.hash } else if (savedPosition) { scrollTo = savedPosition.y } return goTo(scrollTo) }, routes: [ // ], }) ``` -->