intersection observer for svelte
Try it in the Svelte REPL
Svelte REPL.t
# npm
npm i -D svelte-intersection-observer-directive
# Yarn
yarn add -D svelte-intersection-observer-directive
<script>
import intersection from 'svelte-intersection-observer-directive';
</script>
<div
use:intersection={{ threshold: 0.5, once: true }}
on:enterViewport={handleEnterViewport}
on:exitViewport={handleExitViewport}>
Hello world
</div>
Name |
Description |
Type |
Default value |
once |
Unobserve the element after the first intersection event |
boolean |
false |
root |
Containing |
|
|
rootMargin |
Margin offset of the containing element |
string |
"0px" |
threshold |
Percentage of element visibile to trigger an event |
number between 0 and 1, or an array of number s between 0 and 1 |
0 |
MIT