Detect if an element is in the viewport using the Intersection Observer API
Breaking Changes
IntersectionObserverProps
or Entry
TypeScript interfaces from IntersectionObserver.svelte.d.ts
Use the Svelte ComponentProps
utility to extract component props.
import IntersectionObserver from "svelte-intersection-observer";
import type { ComponentProps } from "svelte";
type Props = ComponentProps<IntersectionObserver>;
Fixes
element
and root
prop types should be null | HTMLElement
to support TypeScript strict modeexports
field to package.json
Fixes
exports
field to package.json
to resolve Vite
development warnings (8b2f824, branch)Fixes
threshold
prop type to be number | number[]
(6992399, #70 by @kevinkace)Features
observer
for garbage collection after disconnecting (b961e16)Documentation
Refactoring
null
from element
and root
types as HTMLElement
is already nullable (41a3609)This is a patch release to refresh the documentation published to NPM/Yarn.
Documentation
let:
directive exampleon:observe
, on:intersect
examplesDocumentation
"svelte-intersection-observer"
importsvite
to vite
Refactoring
entry
prop typedef@event
, @slot
artifacts used by sveld to generate initial TypeScript definitionson:observe
: event.detail.isIntersecting
is a boolean
on:intersect
: event.detail.isIntersecting
can only be true
<IntersectionObserver
on:observe={(e) => {
console.log(e.detail.isIntersecting); // boolean
}}
on:intersect={(e) => {
console.log(e.detail.isIntersecting); // true
}}
/>
.svelte.d.ts
as the extension for the component TypeScript definitionThis is a patch release to refresh the documentation published to NPM/Yarn.
Documentation
on:observe
exampleon:observe
and on:intersect
IntersectionObserverEntry
interfaceonce
and intersecting
are more prominentFeatures
rootMargin
changes (https://github.com/metonym/svelte-intersection-observer/pull/12, contributed by @dysfunc)