Scrollspy
Scrollspy can be used to bind a callback function to be called when the element
reaches its scroll position.
Setup
Install via npm
npm install @globocom/scrollspy
Or include one of the browser bundles via a script tag:
<script src="https://unpkg.com/@globocom/scrollspy@0.1.0/dist/scrollspy.min.js"></script>
Options
ScrollSpy.add({
el: DOMElement,
callback: Function,
offset: 200,
reference: "top"
});
Usage
import * as ScrollSpy from "@globocom/scrollspy";
ScrollSpy.add({
el: document.querySelector(".myDiv"),
callback: function() {
}
});
ScrollSpy.add({
el: document.querySelector(".myDiv2"),
offset: 0,
callback: function() {
}
});
ScrollSpy.add({
el: document.querySelector(".myDiv3"),
offset: 40,
reference: "bottom",
callback: function() {
}
});
Debug
There is also available a debug function that highlights "scrollspied"
elements:
ScrollSpy.debug();
Contributing
This project utilizes npm run scripts. See package.json for available scripts.
License
Scrollspy is licensed under the MIT license.