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

ngx-intersection-observer

v1.0.13

Published

Intersection observer for Angular

Downloads

931

Readme

ngx-intersection-observer

Observe visiblity of elements and get notified when they visit/leave the window viewport.

Features

  • Observe elements via IntersectionObserver API or fallback to scroll listener to detect if the element enters/leaves the viewport.
  • Apply or remove classes based on element visiblity
  • Specify threshold, how many precentage of the element need to be visible to trigger intersection.
  • Specify intersection method (IntersectionObserver API or scroll listener)
  • Event binding for intersecting elements.

Dependencies


ngx-intersection-observer | Angular --- | --- 1.0.13 | >=13.x

Install


Install the package via NPM

$ npm install --save  ngx-intersection-observer

Import the module Import the module to your angular application

//...
import { IntersectionObserverModule } from 'ngx-intersection-observer';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    IntersectionObserverModule.forRoot({
      debounce: 50,
      threshold: 30,
      autoRemove: true
    } as IntersectionObserverConfig)
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Usage and Options


Name | Type | Description | Optional | Default --- | --- | --- | --- | --- visitClass | String | List of classes to apply, when the element visits the windows viewport. | Yes leaveClass | String | List of classes to apply, when the element leaves the window viewport. | Yes removeVisitClass | String | List of classes to remove, when the element visits the window viewport. removeLeaveClass | String | List of classes to remove, when the element leaves the windows viewport. | Yes autoRemove | Boolean | true / false If true classes will be removed automatically when the element leaves the viewport, otherwhise use removeVisitClass property. | Yes | true useScroll | Boolean | true / false If true, use scoll listener otherwhise use IntersectionObserver. By default IntersectionBehavior is used, fallback to scroll listener. | Yes | true threshold | Number | Specifies how many precentage of the element need to be visible in the viewport to treat it as intersection. Specify a value between 0% and 100% | Yes | 30% intersection | Event | Function which is called when the element enters/leaves the viewport. | Yes

Example

<div intersectionObserver
     [visitClass]="'bg-blue border'"
     [autoRemove]="true"
     [threshold]="30"
     [useScroll]="false"     
     (intersection)="intersect($event)"
     class="bg-red"
     id="my-div"></div>
</div>
#my-div {
  width: 300px;
  height: 300px;
  margin-top: 2000px;
}

.bg-red {
  background-color: red;
}

.bg-blue{
    background-color: blue;
}

.border{
    border: 5px solid black;

Use with animate.css


Animate.css is a library of ready-to-use, cross-browser animations for use in your web projects. Great for emphasis, home pages, sliders, and attention-guiding hints. https://animate.style/

If you want to apply animations from animate.style, use those two classes to prevent flickering.

.hide-on-init {
  visibility: hidden;
}

.animate__animated {
  visibility: visible !important;
}

Example

<div intersectionObserver
     [visitClass]="'bg-blue border'"
     [autoRemove]="true"
     [threshold]="30"
     [useScroll]="false"     
     (intersection)="intersect($event)"
     class="bg-red hide-on-init"
     id="my-div"></div>
</div>

License


MIT


GitHub @tobiasschiebel | Twitter @SchiebelTobias