UNPKG

@thejlifex/ngx-scroll-spy

Version:

An Angular library that can spy the position of elements (inside a scrollable container) and emit the currently active (visible) element in the viewport.

56 lines (55 loc) 2.28 kB
import { Observable } from 'rxjs'; import { ScrollSpyOptions } from './models/scroll-spy-options'; import { SpyTarget } from './models/spy-target'; import { SpyTargetIsIntersectingEvent } from './models/spy-target-is-intersecting-event'; /** * Encapsulates the logic for scroll spy on a scrollable element (`scrollContainer`). * * Scroll spy uses the [Intersection Observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API). * * Supports window resizing. * * Inspired by: * - https://grafikart.fr/tutoriels/scrollspy-js-page-491 * - https://codepen.io/diaphragm/pen/bGNBVxw * - https://github.com/chefomar/angular-scroll-spy */ export declare class ScrollSpy { private readonly spyTargetIsIntersectingSubject$; /** * Is emitted when a spy-target has transitioned into a state of intersection (`isIntersecting: true`) or out of a state of intersection (`isIntersecting: false`). */ readonly spyTargetIsIntersecting$: Observable<SpyTargetIsIntersectingEvent>; private resizeSubscription?; private spyTargets; private intersectionObserver; private readonly resizeDebounceTime; /** * Defines the (vertical) position of the IntersectionObserver line. * Value between `0` (at the top) and `100` (at the bottom). * * @todo (For a future version of ngx-scroll-spy) This property should be configured by the user. */ private readonly offset; constructor({ scrollContainer }?: ScrollSpyOptions); /** * Adds a spy-target and starts to observe that target. */ addTarget(spyTarget: SpyTarget): void; /** * Removes a spy-target and stops observing that target. */ removeTarget(spyTarget: SpyTarget): void; /** * Stops observing all spy-targets and completes spyTargetIsIntersecting$ subject. */ stopSpying(): void; /** * Initialize IntersectionObserver. */ private initIntersectionObserver; /** * A function which is called when one or more spy-targets have transitioned into a state of intersection (`isIntersecting: true`) or out of a state of intersection (`isIntersecting: false`). */ private intersectionObserverCallback; }