Improved Scroll Events & Scroll Management for web development
Supports horizontal scroll
Written with Typescript
Built with Rxjs
npm install @thalesrc/scroll-manager --save
import scrollManager from "@thalesrc/scroll-manager";
const target = document.querySelector(".scrollable-div");
// Create an observer for the target
const observer = scrollManager.observe(target);
/**
* Subscribe to targets scrollY events
*/
observer.scrollY.subscribe(position => {
console.log(position);
});
/**
* To track window scroll, use `root`
*/
scrollManager.root.scrollY.subscribe(position => {
console.log(position);
});
// Scroll Start
observer.scrollStart.subscribe(position => {
// {top: number, left: number}
});
// Scroll End
observer.scrollEnd.subscribe(position => {
// {top: number, left: number}
});
// Scroll Direction Change
observer.scrollDirectionChange.subscribe(position => {
// 1, 2, 4, 8 (TOP, BOTTOM, LEFT, RIGHT)
});
// Scrolling Down
observer.scrollingDown.subscribe(position => {
// number
});
// Remaining scrollable area to the right in pixels
observer.remainingX.subscribe(position => {
// number
});
By default, scroll-manager throttles scroll events in every 90ms for performance prospects
If you want to capture all events use const observer = scrollManager.observe(target, 0);
thalesrc.github.io/scroll-manager
MIT