Skip to content

Commit 22ab4bc

Browse files
committed
docs: add let: directive example
1 parent 892239d commit 22ab4bc

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,32 @@ Set `once` to `true` for the intersection event to occur only once. The `element
8080
</IntersectionObserver>
8181
```
8282

83-
### on:observe event
83+
### `let:intersecting`
84+
85+
An alternative to binding to the `intersecting` prop is to use the `let:` directive.
86+
87+
In the following example, the "Hello world" element will fade in when its containing element intersects the viewport.
88+
89+
```svelte
90+
<script>
91+
import IntersectionObserver from "svelte-intersection-observer";
92+
import { fade } from "svelte/transition";
93+
94+
let node;
95+
</script>
96+
97+
<header />
98+
99+
<IntersectionObserver element={node} let:intersecting>
100+
<div bind:this={node}>
101+
{#if intersecting}
102+
<div transition:fade={{ delay: 200 }}>Hello world</div>
103+
{/if}
104+
</div>
105+
</IntersectionObserver>
106+
```
107+
108+
### `on:observe` event
84109

85110
The `observe` event is dispatched when the element is first observed and also whenever an intersection event occurs.
86111

@@ -96,7 +121,7 @@ The `observe` event is dispatched when the element is first observed and also wh
96121
</IntersectionObserver>
97122
```
98123

99-
### on:intersect event
124+
### `on:intersect` event
100125

101126
As an alternative to binding the `intersecting` prop, you can listen to the `intersect` event that is dispatched if the observed element is intersecting the viewport.
102127

rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default () => {
2020
z-index: 1;
2121
top: 0;
2222
left: 0;
23+
min-height: 80px;
2324
width: 100%;
2425
padding: 1rem;
2526
background-color: #e0f7f6;

0 commit comments

Comments
 (0)