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

intersection-observer-js

v0.1.2

Published

Plain vanilla JS IntersectionObserver utility, to be used as a mixin

Readme

intersection-observer-js

Plain vanilla JS IntersectionObserver utility, to be used as a mixin.

Installation

$ npm install intersection-observer-js

Basic Usage

You just need to import the utility and then instantiate it with an object:

import inViewport from 'intersection-observer-js';

const sections = document.querySelectorAll(".section");
inViewport({
  $elements: sections,
});

A more complex example would be using special callback and data attribute (see below for API):

import inViewport from 'intersection-observer-js';

const sections = document.querySelectorAll(".section");
inViewport({
  $elements: sections,
  inCallback: (entry) => {
    console.log('intersection crossed at', entry.intersectionRatio);
  },
  dataPos: 'data-intersection-state',
});

Attributes

Object being passed to inViewport has the following attributes.

### $elements

A Nodelist of elements must be provided. These are the elements being observed.

@type {Nodelist}
@required

### observerOptions

The options object passed into the IntersectionObserver() constructor, as per API definition. If not specified it takes the defaults.

@type {Object}

startCallback

Optional callback to be run at the startHook (beginning of an intersection change).

@type {Function}

inCallback

Optional callback to be run at the inHook (intersection entry).

@type {Function}

outCallback

Optional callback to be run at the outHook (intersection exit).

@type {Function}

endCallback

Optional callback to be run at the endHook (end of an intersection change).

@type {Function}

dataPos

Optional string being used to store the position changes.

@type {String}
@default 'data-in-viewport-position'

txtInter

Optional string being used as the position value when entry.isIntersecting.

@type {String}
@default 'intersecting'

txtAbove

Optional string being used as the position value when element being observed is above the definded intersection.

@type {String}
@default 'above'

txtBelow

Optional string being used as the position value when element being observed is below the definded intersection.

@type {String}
@default 'below'

dataDir

Optional string being used to store the direction changes.

@type {String}
@default 'data-in-viewport-direction'

Please note this data attribute is only being set when entry.isIntersecting, and value is built prepending from- string to either txtAbove or txtBelow.

Events execution order

The order of execution of default and hooked events is as follows:

  • startHook
  • Internal update of direction data attribute
  • Internal update of position data attribute
  • inHook / outHook
  • endHook

License

MIT