seng-scroll-tracker
Version:
Class that keeps track of the vertical scroll position of an element.
70 lines (69 loc) • 2.93 kB
TypeScript
import EventDispatcher from 'seng-event';
import Side from './enum/Side';
import ScrollTracker from './ScrollTracker';
/**
* Instance created for every coordinate that a ScrollTracker tracks.
*/
declare class ScrollTrackerPoint extends EventDispatcher {
private scrollPosition;
private pointHeight;
private pointSide;
private pointTracker;
/**
* Boolean indicating if the point is currently in view. Updated when checkInView() is called.
*/
isInView: boolean;
/**
* Boolean indicating if the point is currently within the bounds of the target element.
* Updated when checkInView() is called.
*/
isInBounds: boolean;
/**
* Boolean indicating if the top of the viewport has been scrolled beyond this point
*/
hasScrolledBeyond: boolean;
constructor(scrollPosition: number, pointHeight: number, pointSide: Side, pointTracker: ScrollTracker);
/**
* Change the position of this point. Executes checkInView to check if the point has entered or
* leaved view.
* @param position The position of this points in pixels. This is the distance from the start
* or end of the target element depending on the 'side' parameter, measured horizontally or
* vertically depending on the axis of this ScrollTracker instance.
*/
/**
* @returns {number} The current position of the point in pixels. This is the distance from the
* start or end of the target element depending on the 'side' parameter, measured horizontally or
* vertically depending on the axis of this ScrollTracker instance.
*/
position: number;
/**
* Change the height of this point. Executes checkInView to check if the point has entered or
* leaved view.
* @param height The height of this points in pixels. This is the distance from the start
* or end of the target element depending on the 'side' parameter, measured horizontally or
* vertically depending on the axis of this ScrollTracker instance.
*/
/**
* @returns {number} The current height of the point in pixels. This is the distance from the
* start or end of the target element depending on the 'side' parameter, measured horizontally or
* vertically depending on the axis of this ScrollTracker instance.
*/
height: number;
/**
* @returns {Side} The side of from which the position of this point is measured.
*/
readonly side: Side;
private getInViewValue;
private checkScrollBeyond;
/**
* Checks if this point is in view using it's position and the current scroll position saved on
* the ScrollTracker. Updates the isInView property accordingly.
* @return {boolean} True if this point is in view.
*/
checkInView(scrollingBack?: boolean): boolean;
/**
* Disposes the ScrollTrackerPoint instance.
*/
dispose(): void;
}
export default ScrollTrackerPoint;