From 2e53e8c41664c5aa920ca84e738e95c8a05fb349 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sun, 29 Jan 2023 03:55:13 +0100 Subject: [PATCH] feat: page transition --- guide/animations.md | 72 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/guide/animations.md b/guide/animations.md index 875123f..d394dfe 100644 --- a/guide/animations.md +++ b/guide/animations.md @@ -200,4 +200,74 @@ Learn mode: [Demo](https://sli.dev/demo/starter/7) | [@vueuse/motion](https://mo ## Pages Transitions -> Built-in support for slides is NOT YET provided in the current version. We are planning to add support for them in the next major version. Before that, you can still use your custom styles and libraries to do that. +> Available since v0.39.0 + +Slidev supports page transitions out of the box. You can enable it by setting the `transition` frontmatter option: + +```md +--- +transition: slide-left +--- +``` + +This will give you a nice sliding effects on slide switching. Setting it in the frontmatter will apply to all slides. You can also set different transition per slide. + +### Builtin Transitions + +- `fade` - Crossfade in/out +- `fade-out` - Fade out and then fade in +- `slide-left` - Slides to the left, slide to right when going back +- `slide-right` - Slides to the right, slide to left when going back +- `slide-top` - Slides to the top, slide to bottom when going back +- `slide-bottom` - Slides to the bottom, slide to top when going back + +### Custom Transitions + +Slidev's page transitions are powered by [Vue Transition](https://vuejs.org/guide/built-ins/transition.html). You can provide your custom transitions by: + +```md +--- +transition: my-transition +--- +``` + +and then in your custom stylesheets: + +```css +.my-transition-enter-active, +.my-transition-leave-active { + transition: opacity 0.5s ease; +} + +.my-transition-enter-from, +.my-transition-leave-to { + opacity: 0; +} +``` + +Learn more how it works in [Vue Transition](https://vuejs.org/guide/built-ins/transition.html). + +### Forward & Backward Transitions + +You can specify different transitions for forward and backward navigation using `|` as a separator in the transition name: + +```md +--- +transition: go-forward | go-backward +--- +``` + +With this, when you go from slide 1 to slide 2, the `go-forward` transition will be applied. When you go from slide 2 to slide 1, the `go-backward` transition will be applied. + +### Advanced Usage + +The `transition` field accepts an option that will passed to the [``](https://vuejs.org/api/built-in-components.html#transition) component. For example: + +```md +--- +transition: + name: my-transition + enterFromClass: custom-enter-from + enterActiveClass: custom-enter-active +--- +```