MenuScroll.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <!-- Menu sticky horizontal -->
  2. <!-- TODO: review -->
  3. <template>
  4. <LayoutContainer>
  5. <v-row>
  6. <v-col
  7. cols="12"
  8. >
  9. <v-list
  10. class="menu-container"
  11. density="compact"
  12. :class="{ 'sticky-menu': isSticky }"
  13. >
  14. <div v-for="menu in menus" :key="menu.anchor">
  15. <nuxt-link :to="{ path: '', hash: '#' + menu.anchor }">
  16. <v-list-item
  17. :class="{ active : isSticky && layoutStore.isAnchoredSectionOnScreen[menu.anchor] }"
  18. >
  19. {{ menu.label }}
  20. </v-list-item>
  21. </nuxt-link>
  22. </div>
  23. </v-list>
  24. </v-col>
  25. </v-row>
  26. </LayoutContainer>
  27. </template>
  28. <script setup lang="ts">
  29. import type { PropType } from "@vue/runtime-core";
  30. import type { MenuScroll } from "~/types/interface";
  31. import { useLayoutStore } from "~/stores/layoutStore";
  32. const props = defineProps({
  33. menus: {
  34. type: Array as PropType<Array < MenuScroll >>,
  35. required: true
  36. }
  37. });
  38. const layoutStore = useLayoutStore()
  39. const isSticky: Ref<boolean> = ref(false);
  40. onMounted(() => {
  41. window.addEventListener('scroll', handleScroll);
  42. })
  43. const handleScroll = () => {
  44. isSticky.value = window.scrollY > 800;
  45. }
  46. </script>
  47. <style scoped lang="scss">
  48. .sticky-menu {
  49. position: fixed;
  50. top: 0;
  51. left: 0;
  52. right: 0;
  53. background: white;
  54. box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  55. }
  56. .menu-container {
  57. z-index: 3;
  58. display: flex;
  59. justify-content: space-around;
  60. background: white;
  61. color: #071b1f;
  62. font-family: "Barlow", serif;
  63. font-size: 1rem;
  64. line-height: 19px;
  65. align-items: center;
  66. text-align: center;
  67. letter-spacing: 0.18em;
  68. text-transform: uppercase;
  69. border-bottom: 0.1rem solid #eaeaea;
  70. a {
  71. text-decoration: none;
  72. color: #071b1f;
  73. }
  74. a:hover {
  75. text-decoration: underline;
  76. }
  77. }
  78. .active {
  79. font-weight: 800;
  80. }
  81. </style>