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

scrollparent-polyfill

v1.0.2

Published

A JavaScript polyfill for Element.scrollParent()

Readme

Element.scrollParent() polyfill

A lightweight JavaScript polyfill for Element.scrollParent(), modeled after the standard behavior of scroll container resolution in the CSSOM View and CSS Overflow specifications.

It utilizes get-containing-block to correctly resolve the scroll parent for absolutely and fixed-positioned elements, skipping static ancestor containers that do not clip them.

This project is fully tested using the official Web Platform Tests (WPT).

  • PASS: 17 / 17
  • FAIL: 0 / 17

Features

  • Specification-Compliant Resolution: Resolves standard scroll containers accurately by checking computed overflow-x and overflow-y styles (auto, scroll, hidden).
  • Absolute & Fixed Support: Correctly skips non-containing blocks for absolute and fixed positioned elements to find their true scrolling ancestor.
  • CSS Overflow Propagation: Accounts for UA-specific overflow propagation from the <body> and <html> elements to the viewport.
  • Prototype Polyfill: Automatically polyfills Element.prototype.scrollParent().
  • Flexible API: Can be used as an imported standalone utility or called directly on DOM element prototypes.
  • Fully Typed: Written in TypeScript with standard types exported.
  • ESM Support: Built as an ES Module.
  • WPT Compliant: Tested against the Web Platform Tests for scrollParent.

Installation

npm install scrollparent-polyfill

Usage

1. As a Polyfill

Simply import the package or load the IIFE bundle via CDN to automatically install the method on Element.prototype.

Via Bundler (ESM)

import 'scrollparent-polyfill';

const element = document.querySelector('.my-child-element');

// Call standard camelCase method
const scrollParent = element.scrollParent();

console.log('Scroll parent is:', scrollParent);

Direct Browser Usage (IIFE via CDN)

For direct browser usage without a bundler, you can load the bundled IIFE version from a CDN (such as unpkg):

<!-- Load the polyfill from a CDN -->
<script src="https://unpkg.com/scrollparent-polyfill/dist/scrollparent-polyfill.iife.js"></script>

<script>
  const element = document.querySelector('.my-child-element');
  
  // The polyfill automatically installs the method on Element.prototype
  const scrollParent = element.scrollParent();
  
  console.log('Scroll parent is:', scrollParent);
</script>

2. As a Standalone Utility

If you prefer not to modify the global Element.prototype, you can import the helper function directly:

import { getScrollParent } from 'scrollparent-polyfill';

const element = document.querySelector('.my-child-element');
const scrollParent = getScrollParent(element);

console.log('Scroll parent is:', scrollParent);

API

getScrollParent(node)

Parameters:

  • node (Element): The element to find the scroll parent for.

Returns:

  • Element | null | undefined:
    • The scroll parent element if found.
    • document.scrollingElement if no other scroll parent is found (or if overflow propagates to the viewport).
    • undefined if the element is invalid or not connected to the document.

Development

Installation

To install dependencies for development:

npm install

Building

To build the project (ESM, IIFE, and Types):

npm run build

Testing

To run all tests (unit and Web Platform Tests):

npm run test

Or you can run them individually:

  1. Unit / Integration Tests: Tests using Playwright.

    npm run test:unit
  2. Web Platform Tests (WPT): Runs the official WPT suite for scrollParent.

    # Run WPT tests (requires Python and Firefox)
    npm run test:wpt
    
    # Run WPT tests locally for debugging
    npm run test:wpt:local

License

MIT

Disclaimer

This project is AI-assisted using Google Antigravity, based on the spec and WPT.