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

Full TypeScript signature sourced from the composable file.

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.

Consumed interfaces

IGoToOptions
IGoToInstance

API

Parameters

Input parameters accepted by this 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

Return values

Properties and methods exposed by the composable return object.

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

Examples

Ready-to-paste usage snippets.

Scroll to an anchor element

vue

Scroll to top with custom easing

ts

Horizontal scroll inside a container

ts