npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

nuxt-lenis

v3.0.0

Published

This is a Nuxt wrapper for [Lenis](https://lenis.studiofreight.com/) (by [Studio Freight](https://studiofreight.com/)) – providing smooth scrolling with support for multiple instances in a type-safe and reactive way.

Downloads

1,357

Readme

Nuxt Lenis

This is a Nuxt wrapper for Lenis (by Studio Freight) – providing smooth scrolling with support for multiple instances in a type-safe and reactive way.

Version 2 Notice:
In version 2, the module has been refactored to centrally manage multiple Lenis instances via a Nuxt plugin. Use the provided composable (useLenis) for accessing instance methods and reactive scroll state. The component expects an onScroll prop for scroll callbacks (instead of using emits).


Getting Started

  1. Install the package:

    yarn add nuxt-lenis
  2. Add the module in your nuxt.config:

    export default {
       modules: [
          'nuxt-lenis'
       ]
    }
  3. Wrap your page with the Lenis component in app.vue:

    <template>
       <lenis
          :options="LenisOptions"
          onScroll="handleScroll"
       >
          <NuxtPage />
       </lenis>
    </template>
    
    <script setup lang="ts">
    const handleScroll = (scrollData: any) => {
       console.log("Scroll event:", scrollData);
    }
    </script>

Component Usage

The <lenis> component (located at src/runtime/components/Lenis.vue) accepts the following props:

  • id (String, default: "default"): A unique identifier for your Lenis instance.
  • root (Boolean, default: true): Determines if the window should be used as the scroll container.
  • options (Object): Lenis options (e.g., duration, autoRaf, direction).
  • onScroll (Function): Callback fired whenever a scrolling event is received.

Example:

<template>
   <lenis id="default" :options="LenisOptions" onScroll="handleScroll">
      <NuxtPage />
   </lenis>
</template>

<script setup lang="ts">
const LenisOptions = {
   smooth: true,
   duration: 1.2,
   autoRaf: true,
   direction: 'vertical'
}

const handleScroll = (data: any) => {
   console.log("Scroll detected:", data);
}
</script>

Composable Usage

Access the reactive Lenis API via the composable. By default, useLenis() returns the following properties:

  • createLenis: Function to create and register a Lenis instance.
  • getLenis: Function that returns the Lenis instance (or null if not found).
  • destroyLenis: Function to destroy an instance.
  • scrollState: Function to access the reactive scroll state of an instance.
  • watchScrollState: Function to watch changes to the scroll state.

Single Instance Usage

For many cases, a single instance is sufficient:

<script setup lang="ts">
import { watch } from 'vue';
import { useLenis } from '#imports';

const { scrollState, getLenis } = useLenis();

// Example: retrieve default instance
const instance = getLenis(); // returns the Lenis instance or null

// Watch scroll state changes
watch(scrollState, (state) => {
   console.log("Scroll state:", state);
}, { deep: true });
</script>

Multiple Instances

If you need multiple instances, pass false (or use different IDs on each <lenis> component) and access them by ID:

<template>
   <lenis id="main">
      <NuxtPage />
   </lenis>
   <lenis id="modal">
      <NuxtPage />
   </lenis>
</template>

<script setup lang="ts">
import { useLenis } from '#imports';

// Using multiple instance mode:
const { scrollState, getLenis } = useLenis(false);

// Access the instances by ID
const mainInstance = getLenis("main");
const modalInstance = getLenis("modal");

// Example: Log scroll states for each instance
console.log("Main scroll state:", scrollState("main"));
console.log("Modal scroll state:", scrollState("modal"));
</script>

Plugin API

The Nuxt plugin (located at src/runtime/plugin.ts) exposes the following methods:

  • createLenis(id, options?)
    Creates a new Lenis instance for a given ID and registers it.

  • getLenis(id?)
    Retrieves a Lenis instance by its ID (or the default instance if none is specified).

  • destroyLenis(id)
    Destroys the specified Lenis instance and cleans up its associated state.

  • getScrollState(id?)
    Returns the current scroll state for the specified instance, which is updated reactively.

The composable (useLenis) wraps these methods and provides a streamlined API for your components.


Happy scrolling!