Use the Nuxt.js module
main2.14.0 introduced a dedicated Nuxt module, allowing for easier integration within Nuxt.js projects.repository·main·Indexed 24 days ago
https://github.com/rigor789/vue-scrolltoA lightweight Vue.js library for performing smooth scrolling animations to specific elements or containers. It supports Vue 2, Vue 3, and Nuxt.js, providing both a `v-scroll-to` directive and a programmatic `$scrollTo` method. Key features include customizable duration, easing (via bezier-easing), offsets, and lifecycle callbacks such as `onStart`, `onDone`, and `onCancel`.
2.14.0 introduced a dedicated Nuxt module, allowing for easier integration within Nuxt.js projects.To use vue-scrollto in your Vue application, you must first install it and then register it as a plugin using Vue.use().
const Vue = require('vue')
const VueScrollTo = require('vue-scrollto')
Vue.use(VueScrollTo)Register the plugin using Vue.use(VueScrollTo). You can then use the v-scroll-to directive on any element. You can pass a selector string or a full options object to customize the behavior of specific scrolls.
// Setup
var Vue = require('vue');
var VueScrollTo = require('vue-scrollto');
Vue.use(VueScrollTo);
// Usage in template
// Simple selector
<a href="#" v-scroll-to="'#element'">Scroll to #element</a>
// With custom options
<a href="#" v-scroll-to="{
el: '#element',
container: '#container',
duration: 500,
lazy: false,
easing: 'linear',
offset: -200,
force: true,
cancelable: true,
onStart: onStart,
onDone: onDone,
onCancel: onCancel,
x: false,
y: true
}">
Scroll to #element
</a>2.17.0, the project includes built-in TypeScript bindings and improved type definitions, making it compatible with TypeScript-based Vue projects.You can install vue-scrollto using npm, yarn, or by including it directly in your HTML via CDN. Note that the package was renamed from vue-scrollTo to vue-scrollto.
npm install --save vue-scrollto
# or
yarn add vue-scrollto2.19.0, vue-scrollto includes support for Vue 3 applications.To use vue-scrollto in a Nuxt.js project, add vue-scrollto/nuxt to the modules section of your nuxt.config.js. You can optionally pass configuration options as a second element in the module array.
{
modules: [
'vue-scrollto/nuxt',
// Or if you have custom options...
['vue-scrollto/nuxt', { duration: 300 }],
]
}force parameter (introduced in 2.12.0) allows you to bypass certain checks (like element visibility) to ensure the scroll occurs.offset option (introduced in 2.8.0) can accept a callback function. Since version 2.16.0, this callback can receive additional parameters to help calculate the scroll offset dynamically.container option (introduced in 2.5.0) allows you to specify a different element to act as the scrollable container, rather than scrolling the default window or body.x option to true in your options object.2.20.0 and later, you can use the lazy option. This allows the library to recalculate the target element's position at the time of scrolling, which is useful if the DOM structure or element positions change between the time the directive is applied and when the scroll is triggered.