项目作者: thalesrc

项目描述 :
Improved Scroll Events & Scroll Management
高级语言: TypeScript
项目地址: git://github.com/thalesrc/scroll-manager.git
创建时间: 2018-05-12T21:49:23Z
项目社区:https://github.com/thalesrc/scroll-manager

开源协议:MIT License

下载


Gen Tech

Scroll Manager

travis
codecov
@thalesrch/scroll-manager"">npm
@thalesrc/scroll-manager"">npm
TypeScript
patreon
license

Improved Scroll Events & Scroll Management for web development

Supports horizontal scroll

Written with Typescript

Built with Rxjs

Installation

npm install @thalesrc/scroll-manager --save

Usage

  1. import scrollManager from "@thalesrc/scroll-manager";
  2. const target = document.querySelector(".scrollable-div");
  3. // Create an observer for the target
  4. const observer = scrollManager.observe(target);
  5. /**
  6. * Subscribe to targets scrollY events
  7. */
  8. observer.scrollY.subscribe(position => {
  9. console.log(position);
  10. });
  11. /**
  12. * To track window scroll, use `root`
  13. */
  14. scrollManager.root.scrollY.subscribe(position => {
  15. console.log(position);
  16. });

Some of Available Scroll Event Streams

  1. // Scroll Start
  2. observer.scrollStart.subscribe(position => {
  3. // {top: number, left: number}
  4. });
  5. // Scroll End
  6. observer.scrollEnd.subscribe(position => {
  7. // {top: number, left: number}
  8. });
  9. // Scroll Direction Change
  10. observer.scrollDirectionChange.subscribe(position => {
  11. // 1, 2, 4, 8 (TOP, BOTTOM, LEFT, RIGHT)
  12. });
  13. // Scrolling Down
  14. observer.scrollingDown.subscribe(position => {
  15. // number
  16. });
  17. // Remaining scrollable area to the right in pixels
  18. observer.remainingX.subscribe(position => {
  19. // number
  20. });

Performance

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);

Api Documentation

thalesrc.github.io/scroll-manager

License

MIT