| 1 | --- |
| 2 | tags: [navigation, layout] |
| 3 | description: | |
| 4 | Create custom components that persist across slides. |
| 5 | --- |
| 6 | |
| 7 | # Global Layers |
| 8 | |
| 9 | Global layers allow you to have custom components that **persist** across slides. This could be useful for having footers, cross-slide animations, global effects, etc. |
| 10 | |
| 11 | Slidev provides three layers for this usage, create `global-top.vue`, `global-bottom.vue`, or `custom-nav-controls.vue` under your project root and it will pick up automatically. |
| 12 | |
| 13 | There are also layers for **each** slide: `slide-top.vue` and `slide-bottom.vue`. The usage is similar to the global layers, but they are applied to every slide, so there may be more than one instance of them. |
| 14 | |
| 15 | ::: tip |
| 16 | If you are using `global-top.vue` or `global-bottom.vue` depending on the current navigation state, when exporting, the `--per-slide` option should be used to ensure the correct state is applied to each slide. Or you can use `slide-top.vue` and `slide-bottom.vue` instead. |
| 17 | ::: |
| 18 | |
| 19 | ## Layers relationship |
| 20 | |
| 21 | At z-axis, from top to bottom: |
| 22 | |
| 23 | - NavControls |
| 24 | - Customized Navigation Controls (`custom-nav-controls.vue`) |
| 25 | - Global Top (`global-top.vue`) - single instance |
| 26 | - Slide Top (`slide-top.vue`) - instance per slide |
| 27 | - Slide Content |
| 28 | - Slide Bottom (`slide-bottom.vue`) - instance per slide |
| 29 | - Global Bottom (`global-bottom.vue`) - single instance |
| 30 | |
| 31 | ## Example |
| 32 | |
| 33 | ```html |
| 34 | <!-- global-bottom.vue --> |
| 35 | <template> |
| 36 | <footer class="absolute bottom-0 left-0 right-0 p-2">Your Name</footer> |
| 37 | </template> |
| 38 | ``` |
| 39 | |
| 40 | The text `Your Name` will appear on all your slides. |
| 41 | |
| 42 | ```html |
| 43 | <!-- custom-nav-controls --> |
| 44 | <template> |
| 45 | <button class="icon-btn" title="Next" @click="$nav.next"> |
| 46 | <div class="i-carbon:arrow-right" /> |
| 47 | </button> |
| 48 | </template> |
| 49 | ``` |
| 50 | |
| 51 | The button `Next` will appear in NavControls. |
| 52 | |
| 53 | To enable it conditionally, you can use the <LinkInline link="guide/global-context" /> |
| 54 | |
| 55 | ```html |
| 56 | <!-- hide the footer from Page 4 --> |
| 57 | <template> |
| 58 | <footer |
| 59 | v-if="$nav.currentPage !== 4" |
| 60 | class="absolute bottom-0 left-0 right-0 p-2" |
| 61 | > |
| 62 | Your Name |
| 63 | </footer> |
| 64 | </template> |
| 65 | ``` |
| 66 | |
| 67 | ```html |
| 68 | <!-- hide the footer from "cover" layout --> |
| 69 | <template> |
| 70 | <footer |
| 71 | v-if="$nav.currentLayout !== 'cover'" |
| 72 | class="absolute bottom-0 left-0 right-0 p-2" |
| 73 | > |
| 74 | Your Name |
| 75 | </footer> |
| 76 | </template> |
| 77 | ``` |
| 78 | |
| 79 | ```html |
| 80 | <!-- an example footer for pages --> |
| 81 | <template> |
| 82 | <footer |
| 83 | v-if="$nav.currentLayout !== 'cover'" |
| 84 | class="absolute bottom-0 left-0 right-0 p-2" |
| 85 | > |
| 86 | {{ $nav.currentPage }} / {{ $nav.total }} |
| 87 | </footer> |
| 88 | </template> |
| 89 | ``` |
| 90 | |
| 91 | ```html |
| 92 | <!-- custom-nav-controls --> |
| 93 | <!-- hide the button in Presenter model --> |
| 94 | <template> |
| 95 | <button v-if="!$nav.isPresenter" class="icon-btn" title="Next" @click="$nav.next"> |
| 96 | <div class="i-carbon:arrow-right" /> |
| 97 | </button> |
| 98 | </template> |
| 99 | ``` |
| 100 |