svelte-intersect
a Svelte action for IntersectionObserver ðŸ’
npm i -D svelte-intersect
docs
aboutdemo
import {intersect} from 'svelte-intersect';
<li
use:intersect={{
onintersect: ({intersecting, intersections, el, obeserver, disconnect}) =>
el.classList.toggle('intersecting', intersecting),
ondisconnect: ({intersecting, intersections, el, obeserver}) => { /* */ },
count,
options: {threshold},
}}
>
An options.threshold
of 0
triggers the event when the element is inside the viewport at least a pixel,
and a value of 1
triggers the event when it is fully inside the viewport. See also options.root
and options.rootMargin
in the IntersectionObserver docs.
A count
of 1
disconnects the observer after the element enters and
leaves the viewport one time, like 'once'
for events. Similar for any positive integer.
A count
that's negative or undefined
makes it so it will never automatically
disconnect.
A count
of 0
disables onintersect
and never creates the IntersectionObserver
.
See also the API docs and demo source code.
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50