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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@thejlifex/ngx-scroll-spy

v0.0.2

Published

An Angular library that can spy the position of elements (inside a scrollable container) and emit the currently active (visible) element in the viewport.

Downloads

410

Readme

NgxScrollSpy

NPM NPM downloads

Angular scroll spy library

An Angular library that can automatically spy the position of elements (inside a scrollable container) and emit the currently active (visible) element in the viewport (add and remove the spyActiveClass, default: active).

Features:

  • Works for nested and dynamically added and removed (*ngIf) elements.
  • Supports multiple scroll-spies.
  • Supports window resizing.

View the demo

Installation

npm install @thejlifex/ngx-scroll-spy --save

Step 01: Import the SpyDirective and SpyTargetDirective to your module (or to your standalone component).

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';

import { SpyDirective, SpyTargetDirective } from '@thejlifex/ngx-scroll-spy';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,

    SpyDirective,
    SpyTargetDirective

  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Step 02: Add the spy directive.

app.component.html

<nav>
  <a spy [spyTargetId]="'home'">Home</a>
  <a spy [spyTargetId]="'features'">Features</a>
  <a spy [spyTargetId]="'pricing'">Pricing</a>
</nav>

Step 03: Add the spyTarget directive.

app.component.html

<section spyTarget [spyTargetId]="'home'">Home</section>
<section spyTarget [spyTargetId]="'features'">Features</section>
<section spyTarget [spyTargetId]="'pricing'">Pricing</section>

Step 04: Hightlight the active nav link.

app.component.scss

nav a.active {
  color: blue;
}

Documentation

SpyDirective (spy)

Spies on the spyTarget that has the provided spyTargetId. | @Input() | Type | Required | Default | Description | |---|---|---|---|---| | spyTargetId | string | yes | none | ID of the spyTarget to spy. | | spyTargetContainerId | string | optional | none | ID of the spyTargetContainer containing the spyTarget. | | spyActiveClass | string | optional | 'active' | Class name to add to this element when the spyTarget has transitioned into a state of intersection (is visisble). |

SpyTargetDirective (spyTarget)

Adds this element as spy-target and starts to observe this target. Automatically removes this element as spy-target and stops observing this target when the element is destroyed. | @Input() | Type | Required | Default | Description | |---|---|---|---|---| | spyTargetId | string | yes | none | ID for this spyTarget. | | spyTargetContainerId | string | optional | none | ID for the spyTargetContainer containing this spyTarget. |

SpyTargetContainerDirective (spyTargetContainer)

Creates a scroll-spy on this spy targets container (element). Automatically destroys the scroll-spy when the element is destroyed.

This is useful:

  • when you have multiple (independent) scrollable elements on the same page,
  • or the scrollable element on your page is not the browser default scrollable element, for example <mat-sidenav-content> if you are using Angular Material Sidenav

where you want to have a scroll-spy.

| @Input() | Type | Required | Default | Description | |---|---|---|---|---| | spyTargetContainerId | string | yes | none | ID for this spyTargetContainer. |

Usage with additionally a spyTargetContainer.

Step 01: Import additionally the SpyTargetContainerDirective to your module (or to your standalone component).

import { ..., SpyTargetContainerDirective } from '@thejlifex/ngx-scroll-spy';

...

imports: [
  ...
  SpyTargetContainerDirective
]

Step 02: Add the spyTargetContainer directive.

app.component.html

<nav>
  <a spy [spyTargetId]="'home'" [spyTargetContainerId]="myContainerId">Home</a>
  ...
</nav>

<div spyTargetContainer [spyTargetContainerId]="myContainerId">
  <section spyTarget [spyTargetId]="'home'"  [spyTargetContainerId]="myContainerId">Home</section>
  ...
</div>

License

MIT