MenuScroll.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <!--
  2. Menu de navigation entre les sections d'une page, accrochée au haut de l'écran sur les écrans larges
  3. -->
  4. <template>
  5. <LayoutContainer v-scroll="handleScroll">
  6. <v-row>
  7. <v-col
  8. cols="12"
  9. >
  10. <v-list
  11. class="menu-container"
  12. density="compact"
  13. :class="{ 'sticky-menu': isSticky }"
  14. >
  15. <nuxt-link
  16. v-if="isSticky"
  17. :to="{ path: '', hash: '#top' }"
  18. class="px-3 py-1"
  19. >
  20. <v-icon icon="fa fa-angle-up" />
  21. </nuxt-link>
  22. <div v-for="menu in menus" :key="menu.anchor">
  23. <nuxt-link :to="{ path: '', hash: '#' + menu.anchor }">
  24. <v-list-item
  25. :class="{ active : isSticky && menu.anchor === activeMenuItem }"
  26. >
  27. {{ menu.label }}
  28. </v-list-item>
  29. </nuxt-link>
  30. </div>
  31. </v-list>
  32. </v-col>
  33. </v-row>
  34. </LayoutContainer>
  35. </template>
  36. <script setup lang="ts">
  37. import type { PropType } from "@vue/runtime-core";
  38. import type { MenuScroll } from "~/types/interface";
  39. import { useLayoutStore } from "~/stores/layoutStore";
  40. defineProps({
  41. menus: {
  42. type: Array as PropType<Array < MenuScroll >>,
  43. required: true
  44. }
  45. });
  46. const layoutStore = useLayoutStore()
  47. const isSticky: Ref<boolean> = ref(false);
  48. const activeMenuItem: ComputedRef<string | null> = computed(() => {
  49. return Object.entries(
  50. layoutStore.isAnchoredSectionOnScreen
  51. ).find(
  52. ([key, value]) => value === true
  53. )?.[0] ?? null
  54. })
  55. const handleScroll = () => {
  56. isSticky.value = window.scrollY > 800;
  57. }
  58. </script>
  59. <style scoped lang="scss">
  60. .sticky-menu {
  61. position: fixed;
  62. top: 0 !important;
  63. left: 0;
  64. right: 0;
  65. background: var(--neutral-color);
  66. box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  67. }
  68. .menu-container {
  69. top: -32px;
  70. z-index: 3;
  71. display: flex;
  72. justify-content: center;
  73. background: var(--neutral-color);
  74. color: var(--on-neutral-color);
  75. font-size: 15px;
  76. line-height: 19px;
  77. align-items: center;
  78. text-align: center;
  79. letter-spacing: 0.18em;
  80. text-transform: uppercase;
  81. border-bottom: 0.1rem solid var(--on-neutral-color-extra-light);
  82. a {
  83. text-decoration: none;
  84. color: var(--on-neutral-color);
  85. }
  86. a:hover {
  87. text-decoration: underline;
  88. }
  89. }
  90. .active {
  91. background-color: var(--scroll-menu-primary-color);
  92. color: var(--scroll-menu-on-primary-color);
  93. border-radius: 16px;
  94. padding: 5px;
  95. }
  96. </style>