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

@uniprank/ngx-scrollspy

v2.0.1

Published

Angular library to detect scroll events with a service or directives. Supports standalone components and signals.

Downloads

518

Readme

CI

You can use this angular service to spy scroll events from window or any other scrollable element.

This library implements a service to collect observables from scroll spy directives. It can be used to create your own components or if you prefer use one of the following directives.

See Examples here Example

Installation

First you need to install the npm module:

npm install @uniprank/ngx-scrollspy --save

Setup (Standalone API)

Use provideScrollSpy() in your application config to set up the service:

// app.config.ts
import { ApplicationConfig } from '@angular/core';
import { provideScrollSpy } from '@uniprank/ngx-scrollspy';

export const appConfig: ApplicationConfig = {
  providers: [
    provideScrollSpy({ lookAhead: true })
  ]
};
// main.ts
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { appConfig } from './app/app.config';

bootstrapApplication(AppComponent, appConfig);

Then import the standalone directives directly in your components:

import { Component } from '@angular/core';
import { ScrollSpyDirective, ScrollItemDirective } from '@uniprank/ngx-scrollspy';

@Component({
  selector: 'app-example',
  standalone: true,
  imports: [ScrollSpyDirective, ScrollItemDirective],
  template: `
    <li uniScrollItem="section1">Section 1</li>
    <section uniScrollSpy="section1">Content</section>
  `
})
export class ExampleComponent {}

Available Directives

| Directive | Selector | Description | |-----------|----------|-------------| | ScrollSpyDirective | [uniScrollSpy] | Marks a content section to be tracked by the scroll spy | | ScrollItemDirective | [uniScrollItem] | Marks a navigation item that mirrors the active state | | ScrollElementDirective | [uniScrollElement] | Wraps a custom scrollable container (non-window) |

Using

Spy window scroll

Use ScrollSpyDirective to spy on window as default or set scrollElement to spy on another scrollable element.

import { Component } from '@angular/core';
import { ScrollSpyDirective, ScrollItemDirective, ScrollSpyService } from '@uniprank/ngx-scrollspy';

@Component({
  selector: 'app-example',
  standalone: true,
  imports: [ScrollSpyDirective, ScrollItemDirective],
  template: `<div uniScrollSpy="section-abc"></div>`
})
export class ExampleComponent implements AfterViewInit {
  constructor(private _scrollSpyService: ScrollSpyService) {}

  ngAfterViewInit() {
    this._scrollSpyService.observe('window').subscribe((element) => {
      console.log('ScrollSpy::window: ', element);
    });
  }
}

Spy any element scroll

Use ScrollElementDirective to spy on any element. You must give a unique id to each instance. This unique id is called elementID and you need this elementID to connect your ScrollItemDirective or your ScrollSpyDirective.

import { Component, AfterViewInit } from '@angular/core';
import {
  ScrollSpyDirective,
  ScrollItemDirective,
  ScrollElementDirective,
  ScrollSpyService,
  ScrollObjectInterface
} from '@uniprank/ngx-scrollspy';

@Component({
  selector: 'app-example',
  standalone: true,
  imports: [ScrollSpyDirective, ScrollItemDirective, ScrollElementDirective],
  template: `
    <div uniScrollItem="part2" scrollElement="test">Get class active if part2 is in focus.</div>
    <div uniScrollElement="test" style="max-height: 100px; overflow: auto;">
      <div uniScrollSpy="part1" style="height: 500px;"></div>
      <div uniScrollSpy="part2" style="height: 500px;"></div>
    </div>
  `
})
export class ExampleComponent implements AfterViewInit {
  constructor(private _scrollSpyService: ScrollSpyService) {}

  ngAfterViewInit() {
    this._scrollSpyService.observe('test').subscribe((element: ScrollObjectInterface) => {
      console.log('ScrollSpy::test: ', element);
    });
  }
}

Because ScrollSpyService is a singleton, you can get any ScrollSpy observable from anywhere within your application.

Parameters

You can pass optional parameters to provideScrollSpy():

| Parameter | Value | Description | |-----------|-------|-------------| | lookAhead | boolean | Set the first item active even if it's not already in the viewport | | activateOnlySetItems | boolean | Only activate items when fully within the viewport | | attributeType | 'id' | 'data-id' | Which HTML attribute to set on spy elements (default: 'id') |

provideScrollSpy({ lookAhead: true })

TODO:

  • Finish unit tests

License

MIT