JSPM

scrollbar-observer

0.1.3
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • 0
    • Score
      100M100P100Q29877F
    • License ISC

    Observe the appearance and disappearance of the scroll bar of an element

    Package Exports

    • scrollbar-observer

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (scrollbar-observer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    scrollbar-observer

    Observe the appearance and disappearance of the scroll bar of an element

    Installation

    npm i scrollbar-observer

    useage

    const dom = document.getElementById('want-to-observer');
    
    const scrollbarObserver = new ScrollbarObserver(
      dom,
      (event: ScrollObserverEvent, preStatus: ScrollObserverEvent) => {
        if (event.scrollX) {
          console.log('A scroll bar appears in the horizontal direction');
        }
        if (event.scrollY) {
          console.log('A scroll bar appears in the vertical direction');
        }
      }
    );
    // Cancel the observation and destroy the observer
    scrollbarObserver.dispose();

    Under normal circumstances, the program automatically updates the observation strategy according to the changes in the observed dom (such as the addition and removal of child elements).

    But sometimes it will fail (for example, the browser does not support the MutationObserver API), you can call it manually to recreate the dom listener

    scrollbarObserver.reListen();