scroll-parents
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

scroll-parents

Simple function that returns an array with all the scrolling parent nodes of a given element. Useful if an element needs to listen to the scroll event of all it's parent nodes.

Install

npm install scroll-parents --save

Examples

With scrolling parents

<html>
    <body>
        <div id="scrolling-parent" style="overflow:scroll;">
            <div id="my-id"></div>
        </div>
    </body>
</html>
import scrollParents from 'scroll-parents';
 
const myNode = document.getElementById('my-id');
 
scrollParents(myNode); // Output: [scrollingParent, Window]

The array is ordered from closest scrolling parent (left) to most distant scrolling parent (right), always ending with the Window object.

Without scrolling parents

<html>
    <body>
        <div id="my-id"></div>
    </body>
</html>
import scrollParents from 'scroll-parents';
 
const myNode = document.getElementById('my-id');
 
scrollParents(myNode); // Output: [Window]

License

ISC

Package Sidebar

Install

npm i scroll-parents

Weekly Downloads

6

Version

1.0.4

License

ISC

Unpacked Size

7.03 kB

Total Files

9

Last publish

Collaborators

  • eiriklillebo