useGoTo

Commons
stable

Returns a scrollTo function that smoothly scrolls a container or the window to a target element, component instance, CSS selector, or numeric offset. Supports both vertical and horizontal scrolling, RTL awareness, and custom easing/duration options.

API

Signature

Signature TypeScript complète extraite du fichier du composable.

typescript

useGoTo reads RTL direction from the global locale and the injected IGoToInstance. Per-call options are deep-merged with the instance defaults, so you can customise the duration globally and override it for specific calls.

Interfaces consommées

IGoToOptions
IGoToInstance

API

Paramètres

Paramètres d'entrée acceptés par ce composable.

_options
Partial<IGoToOptions>
{}
options
Partial<IGoToOptions>
Default options applied to every go() call made through this instance. Can be overridden per-call.
options.duration
number
300
Scroll animation duration in milliseconds.
options.easing
TEasingFunction | string
'easeInOutCubic'
Easing function name or a custom function (t: number) => number controlling the animation curve.
options.offset
number
0
Pixel offset applied to the final scroll position (positive = scroll further, negative = stop earlier).
options.container
ComponentPublicInstance | HTMLElement | string
'html'
Scrollable container element or selector. Defaults to the document root.

API

Valeurs de retour

Propriétés et méthodes exposées par l'objet retourné par le composable.

go
Scroll vertically to the target. Accepts a Vue component instance, an HTMLElement, a CSS selector string, or a numeric pixel offset.
go.horizontal
Scroll horizontally to the target using the same resolution logic as go().

Usage

Exemples

Extraits de code prêts à coller.

Scroll to an anchor element

vue

Scroll to top with custom easing

ts

Horizontal scroll inside a container

ts