Skip to content

Commit f04225f

Browse files
committed
document local transitions
1 parent b815ac7 commit f04225f

File tree

8 files changed

+79
-0
lines changed

8 files changed

+79
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<script>
2+
import { slide } from 'svelte/transition';
3+
4+
let showItems = true;
5+
let i = 5;
6+
let items = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'];
7+
</script>
8+
9+
<style>
10+
div {
11+
padding: 0.5em 0;
12+
border-top: 1px solid #eee;
13+
}
14+
</style>
15+
16+
<label>
17+
<input type="checkbox" bind:checked={showItems}>
18+
show list
19+
</label>
20+
21+
<label>
22+
<input type="range" bind:value={i} max=10>
23+
24+
</label>
25+
26+
{#if showItems}
27+
{#each items.slice(0, i) as item}
28+
<div transition:slide>
29+
{item}
30+
</div>
31+
{/each}
32+
{/if}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<script>
2+
import { slide } from 'svelte/transition';
3+
4+
let showItems = true;
5+
let i = 5;
6+
let items = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'];
7+
</script>
8+
9+
<style>
10+
div {
11+
padding: 0.5em 0;
12+
border-top: 1px solid #eee;
13+
}
14+
</style>
15+
16+
<label>
17+
<input type="checkbox" bind:checked={showItems}>
18+
show list
19+
</label>
20+
21+
<label>
22+
<input type="range" bind:value={i} max=10>
23+
24+
</label>
25+
26+
{#if showItems}
27+
{#each items.slice(0, i) as item}
28+
<div transition:slide|local>
29+
{item}
30+
</div>
31+
{/each}
32+
{/if}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: Local transitions
3+
---
4+
5+
Ordinarily, transitions will play on elements when any container block is added or destroyed. In the example here, toggling the visibility of the entire list also applies transitions to individual list elements.
6+
7+
Instead, we'd like transitions to play only when individual items are added and removed — on other words, when the user drags the slider.
8+
9+
We can achieve this with a *local* transition, which only plays when the immediate parent block is added or removed:
10+
11+
```html
12+
<div transition:slide|local>
13+
{item}
14+
</div>
15+
```

0 commit comments

Comments
 (0)