@solid-primitives/scroll
Version:
Reactive primitives to react to element/window scrolling.
39 lines (38 loc) • 1.53 kB
TypeScript
import { type Accessor } from "solid-js";
export declare function getScrollParent(node: Element | null): Element;
export declare function isScrollable(node: Element): boolean;
export type Position = {
x: number;
y: number;
};
/**
* Get an `{ x: number, y: number }` object of element/window scroll position.
*/
export declare function getScrollPosition(target: Element | Window | undefined): Position;
/**
* Reactive primitive providing a store-like object with current scroll position of specified target.
* @param target element/window to listen to scroll events. can be a reactive singal.
* @returns a store-like reactive object `{ x: number, y: number }` of current scroll position of {@link target}
* @example
* // target will be window by default
* const windowScroll = createScrollPosition();
*
* createEffect(() => {
* // returned object is a reactive store-like structure
* windowScroll.x; // => number
* windowScroll.y; // => number
* });
*/
export declare function createScrollPosition(target?: Accessor<Element | Window | undefined> | Element | Window): Readonly<Position>;
/**
* Returns a reactive object with current window scroll position.
*
* This is a [singleton root](https://github.com/solidjs-community/solid-primitives/tree/main/packages/rootless#createSingletonRoot) primitive.
*
* @example
* const scroll = useWindowScrollPosition();
* createEffect(() => {
* console.log(scroll.x, scroll.y)
* })
*/
export declare const useWindowScrollPosition: () => Readonly<Position>;