| 1 | --- |
| 2 | name: animations |
| 3 | description: Click animations, motion effects, and slide transitions |
| 4 | --- |
| 5 | |
| 6 | # Animations |
| 7 | |
| 8 | Click animations, motion effects, and slide transitions. |
| 9 | |
| 10 | ## Click Animations |
| 11 | |
| 12 | ### v-click Directive |
| 13 | |
| 14 | ```md |
| 15 | <div v-click>Appears on click</div> |
| 16 | <div v-click>Appears on next click</div> |
| 17 | ``` |
| 18 | |
| 19 | ### v-clicks Component |
| 20 | |
| 21 | Animate list items: |
| 22 | |
| 23 | ```md |
| 24 | <v-clicks> |
| 25 | |
| 26 | - Item 1 |
| 27 | - Item 2 |
| 28 | - Item 3 |
| 29 | |
| 30 | </v-clicks> |
| 31 | ``` |
| 32 | |
| 33 | With depth for a nested list that is the only child: |
| 34 | |
| 35 | ```md |
| 36 | <v-clicks depth="2"> |
| 37 | |
| 38 | - Parent 1 |
| 39 | - Child 1 |
| 40 | - Child 2 |
| 41 | - Parent 2 |
| 42 | |
| 43 | </v-clicks> |
| 44 | ``` |
| 45 | |
| 46 | `lists` and `tables` do the same when lists and tables sit next to paragraphs or each other. The number is the depth. `lists="1"` reveals top-level items, `lists="2"` also reveals nested items, `tables="1"` reveals body rows, and `tables="2"` reveals body cells. |
| 47 | |
| 48 | ```md |
| 49 | <v-clicks lists="2" tables="1"> |
| 50 | |
| 51 | Intro paragraph. |
| 52 | |
| 53 | - Item 1 |
| 54 | - Nested item |
| 55 | - Item 2 |
| 56 | |
| 57 | | Name | Priority | |
| 58 | | ---- | -------- | |
| 59 | | Alpha | High | |
| 60 | |
| 61 | </v-clicks> |
| 62 | ``` |
| 63 | |
| 64 | ### Click Positioning |
| 65 | |
| 66 | Relative positioning: |
| 67 | ```md |
| 68 | <div v-click>1st (default)</div> |
| 69 | <div v-click="+1">2nd</div> |
| 70 | <div v-click="-1">Same as previous</div> |
| 71 | ``` |
| 72 | |
| 73 | Absolute positioning: |
| 74 | ```md |
| 75 | <div v-click="3">Appears on click 3</div> |
| 76 | <div v-click="[2,5]">Visible clicks 2-5</div> |
| 77 | ``` |
| 78 | |
| 79 | ### v-after |
| 80 | |
| 81 | Show with previous element: |
| 82 | |
| 83 | ```md |
| 84 | <div v-click>Main element</div> |
| 85 | <div v-after>Appears with main element</div> |
| 86 | ``` |
| 87 | |
| 88 | ### v-switch |
| 89 | |
| 90 | Conditional rendering by click: |
| 91 | |
| 92 | ```md |
| 93 | <v-switch> |
| 94 | <template #1>First state</template> |
| 95 | <template #2>Second state</template> |
| 96 | <template #3>Third state</template> |
| 97 | </v-switch> |
| 98 | ``` |
| 99 | |
| 100 | ## Custom Click Count |
| 101 | |
| 102 | ```md |
| 103 | --- |
| 104 | clicks: 10 |
| 105 | --- |
| 106 | ``` |
| 107 | |
| 108 | Or starting from specific count: |
| 109 | |
| 110 | ```md |
| 111 | --- |
| 112 | clicksStart: 5 |
| 113 | --- |
| 114 | ``` |
| 115 | |
| 116 | ## Motion Animations |
| 117 | |
| 118 | Using @vueuse/motion: |
| 119 | |
| 120 | ```md |
| 121 | <div |
| 122 | v-motion |
| 123 | :initial="{ x: -100, opacity: 0 }" |
| 124 | :enter="{ x: 0, opacity: 1 }" |
| 125 | > |
| 126 | Animated content |
| 127 | </div> |
| 128 | ``` |
| 129 | |
| 130 | Click-based motion: |
| 131 | |
| 132 | ```md |
| 133 | <div |
| 134 | v-motion |
| 135 | :initial="{ scale: 1 }" |
| 136 | :click-1="{ scale: 1.5 }" |
| 137 | :click-2="{ scale: 1 }" |
| 138 | > |
| 139 | Scales on clicks |
| 140 | </div> |
| 141 | ``` |
| 142 | |
| 143 | ## Slide Transitions |
| 144 | |
| 145 | In headmatter (all slides): |
| 146 | |
| 147 | ```md |
| 148 | --- |
| 149 | transition: slide-left |
| 150 | --- |
| 151 | ``` |
| 152 | |
| 153 | Per-slide: |
| 154 | |
| 155 | ```md |
| 156 | --- |
| 157 | transition: fade |
| 158 | --- |
| 159 | ``` |
| 160 | |
| 161 | ### Built-in Transitions |
| 162 | |
| 163 | - `fade` / `fade-out` |
| 164 | - `slide-left` / `slide-right` |
| 165 | - `slide-up` / `slide-down` |
| 166 | - `view-transition` (View Transitions API) |
| 167 | |
| 168 | ### Directional Transitions |
| 169 | |
| 170 | Different transitions for forward/backward: |
| 171 | |
| 172 | ```md |
| 173 | --- |
| 174 | transition: slide-left | slide-right |
| 175 | --- |
| 176 | ``` |
| 177 | |
| 178 | ### Custom Transitions |
| 179 | |
| 180 | Define CSS classes: |
| 181 | |
| 182 | ```css |
| 183 | .my-transition-enter-active, |
| 184 | .my-transition-leave-active { |
| 185 | transition: all 0.5s ease; |
| 186 | } |
| 187 | .my-transition-enter-from, |
| 188 | .my-transition-leave-to { |
| 189 | opacity: 0; |
| 190 | transform: translateX(100px); |
| 191 | } |
| 192 | ``` |
| 193 | |
| 194 | Use: `transition: my-transition` |
| 195 | |
| 196 | ## CSS Classes |
| 197 | |
| 198 | Animation targets get these classes: |
| 199 | - `.slidev-vclick-target` - Animated element |
| 200 | - `.slidev-vclick-hidden` - Hidden state |
| 201 | - `.slidev-vclick-current` - Current click target |
| 202 | - `.slidev-vclick-prior` - Previously shown |
| 203 | |
| 204 | ## Default Animation CSS |
| 205 | |
| 206 | ```css |
| 207 | .slidev-vclick-target { |
| 208 | transition: opacity 100ms ease; |
| 209 | } |
| 210 | .slidev-vclick-hidden { |
| 211 | opacity: 0; |
| 212 | pointer-events: none; |
| 213 | } |
| 214 | ``` |
| 215 |