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 🙏

© 2025 – Pkg Stats / Ryan Hefner

scrollclass

v0.3.0

Published

Add/remove classes to elements as the user scrolls with IntersectionObserver

Downloads

8

Readme

scrollclass

Scrollclass is a small library for adding and removing classes to elements as elements come into and out of the viewport. These classes would typically be used to trigger CSS3 animations. It uses the IntersectionObserver API and will not work on browsers that do not provide this API. Since it's still relatively new, it's recommended to use a polyfill like this one to provide support to older browsers.

Installation

Download scrollclass.js and include it in HTML:

<script src="path/to/scrollclass.js"></script>

If you are using a bundler like webpack, you can also install it through npm:

$ npm install --save scrollclass

and import it:

// ES6
import scrollclass from 'scrollclass';

// require()
const scrollclass = require('scrollclass');

Usage

See here for a complete example.


// scrollclass accepts a list of triggers
let sc = scrollclass([
    {
        // element to apply the class to
        // for all options that accept elements, you can give a string of the
        // element's ID or an actual Element object
        target: 'target',
        // which class to add or remove
        class: 'active',
        // it will have the class when at least 75% of the trigger element is visible
        // default: 0
        threshold: 0.75,
        // which element to check visibility of
        // if not specified, the target element is used
        trigger: 'trigger',
        // once = true: once the target element is first given the class, it will never be removed
        // once = false (default): the class will be removed when the condition is no longer met
        once: false,
        // class the target element should have when the trigger is not visible
        // by default, no class will be added (the main class will just be removed)
        alternateClass: 'inactive',
        // inverts all operations
        // default: false
        invert: false,
        // margin to add around the viewport's bounding box
        // specified the same way as the CSS margin property (top right bottom left)
        // default: '0px'
        margin: '20px',
        // root element that visibility is computed relative to
        // must be an ancestor of the trigger element
        // default: browser viewport
        root: 'rootElem'
    } // can specify as many more as you want, or make multiple calls to scrollclass
]);

// disable all triggers without changing classes on any target elements
sc.disable();