Skip to content

Commit 80d9878

Browse files
committed
Doc: Raise importance of global vs local transitions
1 parent e2bbc56 commit 80d9878

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

documentation/docs/03-template-syntax/13-transition.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ title: transition:
44

55
A _transition_ is triggered by an element entering or leaving the DOM as a result of a state change.
66

7+
Transitions are _local_ by default. Local transitions only play when the block they belong to is created or destroyed, _not_ when parent blocks are created or destroyed.
8+
9+
## Global Transitions
10+
11+
You can specify a _global_ transition should by appending the modifier `|global` to the directive.
12+
13+
```svelte
14+
{#if x}
15+
{#if y}
16+
<p transition:fade>fades in and out only when y changes</p>
17+
18+
<p transition:fade|global>fades in and out when x or y change</p>
19+
{/if}
20+
{/if}
21+
```
22+
23+
## Bidirectional Transitions
24+
725
When a block (such as an `{#if ...}` block) is transitioning out, all elements inside it, including those that do not have their own transitions, are kept in the DOM until every transition in the block has been completed.
826

927
The `transition:` directive indicates a _bidirectional_ transition, which means it can be smoothly reversed while the transition is in progress.
@@ -26,19 +44,6 @@ The `transition:` directive indicates a _bidirectional_ transition, which means
2644

2745
A selection of built-in transitions can be imported from the [`svelte/transition`](svelte-transition) module.
2846

29-
## Local vs global
30-
31-
Transitions are local by default. Local transitions only play when the block they belong to is created or destroyed, _not_ when parent blocks are created or destroyed.
32-
33-
```svelte
34-
{#if x}
35-
{#if y}
36-
<p transition:fade>fades in and out only when y changes</p>
37-
38-
<p transition:fade|global>fades in and out when x or y change</p>
39-
{/if}
40-
{/if}
41-
```
4247

4348
## Transition parameters
4449

0 commit comments

Comments
 (0)