0.8.0 • Published 2 years ago

@fuz.dev/svelte_intersect v0.8.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@fuz.dev/svelte_intersect

a Svelte action for IntersectionObserver

Usage

npm i -D @fuz.dev/svelte_intersect
import {intersect} from '@fuz.dev/svelte_intersect';

intersect is a Svelte action that calls your callback when el enters or leaves the viewport:

<div use:intersect={(intersecting, el, disconnect) => /* ... */}>
export interface Intersect_Callback {
	(intersecting: boolean, el: HTMLElement | SVGElement, disconnect: () => void): void;
}

For more complex behavior:

<div use:intersect={{
  cb: (intersecting, el, disconnect) => /* ... */,
  count: 1, // 1 is like 'once', 0 disables, <0 infinite
  options: {threshold, root, rootMagin}, // IntersectionObserver options
}}>
propertydefaultdescription
cbcalled every time the element enters or leaves the viewport until the action's observer is disconnected
count?undefinedpass 1 to disconnect after el enters and leaves the viewport one time, similar to 'once' for an event - disable the callback with 0, and never disconnect with undefined or a negative number like -1
options?undefinedIntersectionObserverInit options forwarded to the IntersectionObserver

For more see the IntersectionObserver docs on MDN and the demo at intersect.fuz.dev.

License

MIT

0.8.0

2 years ago

0.7.0

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.1

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago