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

@ppasmik/react-scroll-trigger

v1.0.1

Published

Modern React component for scroll-based triggers and animations with TypeScript support. A rewritten and modernized version of the original react-scroll-trigger package.

Readme

@ppasmik/react-scroll-trigger

npm version NPM license npm downloads Coverage Status Build Status

A modern, TypeScript-based React component for monitoring scroll events and triggering callbacks when elements enter, exit, or progress through the viewport. This is a rewritten and modernized version of the original react-scroll-trigger package.

Each callback includes progress and velocity parameters, enabling precise control over animations and transitions based on scroll position and speed.

Installation

npm install @ppasmik/react-scroll-trigger

or via Yarn:

yarn add @ppasmik/react-scroll-trigger

Usage

import ScrollTrigger from '@ppasmik/react-scroll-trigger';

const MyComponent = () => {
  const [visible, setVisible] = useState(false);

  const onEnterViewport = () => {
    setVisible(true);
  };

  const onExitViewport = () => {
    setVisible(false);
  };

  return (
    <ScrollTrigger onEnter={onEnterViewport} onExit={onExitViewport}>
      <div className={`container ${visible ? 'container-animate' : ''}`} />
    </ScrollTrigger>
  );
};

The ScrollTrigger component is designed to be highly flexible. You can use it:

  • As a standalone element without children
<ScrollTrigger onEnter={handleEnter} onExit={handleExit} />
  • With children to receive events based on their dimensions
<ScrollTrigger onEnter={handleEnter} onProgress={handleProgress}>
  <section>
    <h1>Your content here</h1>
  </section>
</ScrollTrigger>

Common use cases include:

  • Triggering animations when elements become visible
  • Loading content dynamically based on scroll position
  • Creating scroll-based transitions and effects
  • Implementing infinite scroll functionality

Props

| Prop | Type | Default | Description | | ---------------- | -------------------- | ------------------------ | -------------------------------------------------------------------- | | component | ElementType | 'div' | React component or HTML element to render as wrapper | | containerRef | HTMLElement ⎮ string | document.documentElement | Scrolling container reference | | throttleResize | number | 100 | Resize event throttle in ms | | throttleScroll | number | 100 | Scroll event throttle in ms | | triggerOnLoad | boolean | true | Whether to trigger onEnter on mount | | onEnter | function | - | Called when element enters viewport ({progress, velocity}) => void | | onExit | function | - | Called when element exits viewport ({progress, velocity}) => void | | onProgress | function | - | Called during scroll ({progress, velocity}) => void |

Standard React props (className, style, etc.) are also supported and will be passed to the wrapper element.

Technical Details

The component uses React hooks for efficient state management:

  • useRef to track the DOM element position
  • useState for viewport visibility and scroll tracking
  • useEffect for handling scroll and resize events with proper cleanup

Visibility detection:

  • Uses getBoundingClientRect() for accurate element position calculation
  • Progress is calculated based on element's position relative to viewport:
    progress = 1 - elementRect.bottom / (viewportEnd + elementRect.height);
  • Velocity is derived from scroll position changes over time
  • All calculations are throttled (default 100ms) to optimize performance

The component is designed to work with both window-level scrolling and custom scroll containers (via containerRef prop), making it suitable for various layout scenarios.

License

MIT © [Peter Pasmik]

Acknowledgments

This package is a TypeScript rewrite of the original react-scroll-trigger package, modernized with current React practices and enhanced type safety.