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 🙏

© 2026 – Pkg Stats / Ryan Hefner

universal-virtual-scroll

v1.0.2

Published

A lightweight and framework-agnostic virtual scrolling library.

Readme

universal-virtual-scroll

npm license bundle size typescript framework

A lightweight and framework-agnostic virtual scrolling library for efficiently rendering large lists and grids with smooth performance.


Installation

npm install universal-virtual-scroll

Import

import {
  UniversalVirtualScroll
} from 'universal-virtual-scroll';

Angular Example

app.component.html

<div #viewport class="viewport">

  <div
    #content
    [style.paddingTop.px]="paddingTop"
    [style.paddingBottom.px]="paddingBottom">

    @for (item of visibleItems; track item.name) {

      <div class="card">

        {{ item.name }}

      </div>

    }

  </div>

</div>

app.component.ts

import {
  AfterViewInit,
  Component,
  ElementRef,
  ViewChild
} from '@angular/core';

import {
  UniversalVirtualScroll
} from 'universal-virtual-scroll';

@Component({
  selector: 'app-root',
  standalone: true,
  templateUrl: './app.component.html',
  styleUrl: './app.component.css'
})
export class AppComponent
implements AfterViewInit {

  @ViewChild('viewport')
  viewport!: ElementRef;

  @ViewChild('content')
  content!: ElementRef;

  visibleItems: any[] = [];

  paddingTop = 0;

  paddingBottom = 0;

  items = Array.from(
    { length: 100000 },
    (_, i) => ({
      name: `Item ${i + 1}`
    })
  );

  ngAfterViewInit(): void {

    new UniversalVirtualScroll({

      viewport:
        this.viewport.nativeElement,

      content:
        this.content.nativeElement,

      items: this.items,

      itemHeight: 100,

      itemWidth: 200,

      onUpdate: (
        items,
        top,
        bottom
      ) => {

        this.visibleItems = items;

        this.paddingTop = top;

        this.paddingBottom = bottom;
      }
    });
  }
}

app.component.css

.viewport {
  height: 100vh;
  overflow-y: auto;
}

.card {
  height: 100px;
}

React Example

App.jsx

import {
  useEffect,
  useRef,
  useState
} from 'react';

import {
  UniversalVirtualScroll
} from 'universal-virtual-scroll';

function App() {

  const viewportRef = useRef(null);

  const contentRef = useRef(null);

  const [visibleItems, setVisibleItems] =
    useState([]);

  const [paddingTop, setPaddingTop] =
    useState(0);

  const [paddingBottom, setPaddingBottom] =
    useState(0);

  const items = Array.from(
    { length: 100000 },
    (_, i) => ({
      name: `Item ${i + 1}`
    })
  );

  useEffect(() => {

    const virtualScroll =
      new UniversalVirtualScroll({

        viewport:
          viewportRef.current,

        content:
          contentRef.current,

        items,

        itemHeight: 100,

        itemWidth: 200,

        onUpdate: (
          items,
          top,
          bottom
        ) => {

          setVisibleItems(items);

          setPaddingTop(top);

          setPaddingBottom(bottom);
        }
      });

    return () => {

      virtualScroll.destroy();

    };

  }, []);

  return (

    <div
      ref={viewportRef}
      className="viewport">

      <div
        ref={contentRef}
        style={{
          paddingTop,
          paddingBottom
        }}>

        {

          visibleItems.map(item => (

            <div
              key={item.name}
              className="card">

              {item.name}

            </div>

          ))
        }

      </div>

    </div>
  );
}

export default App;

App.css

.viewport {
  height: 100vh;
  overflow-y: auto;
}

.card {
  height: 100px;
}

Next.js Example

app/page.jsx

'use client';

import {
  useEffect,
  useRef,
  useState
} from 'react';

import {
  UniversalVirtualScroll
} from 'universal-virtual-scroll';

export default function Home() {

  const viewportRef = useRef(null);

  const contentRef = useRef(null);

  const [visibleItems, setVisibleItems] =
    useState([]);

  const [paddingTop, setPaddingTop] =
    useState(0);

  const [paddingBottom, setPaddingBottom] =
    useState(0);

  const items = Array.from(
    { length: 100000 },
    (_, i) => ({
      name: `Item ${i + 1}`
    })
  );

  useEffect(() => {

    const virtualScroll =
      new UniversalVirtualScroll({

        viewport:
          viewportRef.current,

        content:
          contentRef.current,

        items,

        itemHeight: 100,

        itemWidth: 200,

        onUpdate: (
          items,
          top,
          bottom
        ) => {

          setVisibleItems(items);

          setPaddingTop(top);

          setPaddingBottom(bottom);
        }
      });

    return () => {

      virtualScroll.destroy();

    };

  }, []);

  return (

    <div
      ref={viewportRef}
      className="viewport">

      <div
        ref={contentRef}
        style={{
          paddingTop,
          paddingBottom
        }}>

        {

          visibleItems.map(item => (

            <div
              key={item.name}
              className="card">

              {item.name}

            </div>

          ))
        }

      </div>

    </div>
  );
}

app/globals.css

.viewport {
  height: 100vh;
  overflow-y: auto;
}

.card {
  height: 100px;
}

Configuration

| Option | Type | Description | |---|---|---| | viewport | HTMLElement | Scroll container | | content | HTMLElement | Content wrapper | | items | Array | Full dataset | | itemHeight | Number | Item height | | itemWidth | Number | Item width | | onUpdate | Function | Update callback |


Methods

updateItems

virtualScroll.updateItems(newItems);

destroy

virtualScroll.destroy();

Important

  • viewport must have fixed height
  • viewport must use overflow-y: auto
  • itemHeight must match actual item height
  • itemWidth must match actual item width

License

MIT