This is a Nuxt wrapper for Lenis by Studio Freight. Thank them for the incredible tool.
yarn add nuxt-lenis
- Add
nuxt-lenis
to your modules in nuxt.config - In your
app.vue
file, wrap the nuxt page in the lenis component<lenis :options="LenisOptions" @initiated="foo" @scroll="fooBar" > <NuxtPage /> </lenis>
<!-- You can pass in true or false into useLenis if you want to use more than one lenis instance. Defaults to single instance (true) -->
const {scrollState, lenis} = useLenis()
watch(scrollState, (val) => {
console.log("scrollState", val);
},{deep:true});
If you have multiple instances of Lenis you can get each one via an ID set ont he Lenis component
<lenis id="base" >
<NuxtPage />
</lenis>
<lenis id="modal" >
<NuxtPage />
</lenis>
<!-- script -->
const {scrollState, lenis} = useLenis(false)
scrollState.value.base
lenis.value.base
scrollState.value.modal
lenis.value.modal