UseObserverCreate
katanakit-js / useObserverCreate
Function: useObserverCreate()
Section titled “Function: useObserverCreate()”function useObserverCreate( key, callback, options?, autoUnobserve?): void;Defined in: infrastructure/observer/observer.service.ts:70
Creates an IntersectionObserver under the given key. If an observer with the same key already exists, it is disconnected first.
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
key |
string |
undefined |
A unique identifier for this observer. |
callback |
ObserverCallback |
undefined |
Invoked when an observed element enters the viewport. |
options? |
IntersectionObserverInit |
... |
IntersectionObserver options (default: { threshold: 0.1 }). |
autoUnobserve? |
boolean |
true |
Whether to automatically unobserve after first intersection (default: true). |
Returns
Section titled “Returns”void
Example
Section titled “Example”useObserverCreate("hero", (entry) => { console.log("Hero is visible!", entry.target);}, { threshold: 0.5 });