scroll-parents
v1.0.4
Published
A function to get all the scrolling parents of an html element.
Downloads
164
Maintainers
Readme
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