MenuScroll.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <LayoutContainer>
  3. <v-row >
  4. <v-col
  5. cols="12"
  6. class="menu-container"
  7. :class="{ 'sticky-menu': isSticky }"
  8. >
  9. <div
  10. v-for="menu in menus"
  11. :key="menu.label"
  12. @click="navigate(menu)"
  13. >
  14. <v-chip
  15. v-if="activeMenu === menu.label"
  16. class="active-menu"
  17. >
  18. {{
  19. menu.label
  20. }}
  21. </v-chip>
  22. <span v-else>{{ menu.label }}</span>
  23. </div>
  24. </v-col>
  25. </v-row>
  26. </LayoutContainer>
  27. </template>
  28. <script setup>
  29. import { ref, onMounted, onUnmounted } from 'vue';
  30. const isSticky = ref(false);
  31. const handleScroll = () => {
  32. const scrollPosition = window.scrollY;
  33. if (scrollPosition > 800) {
  34. isSticky.value = true;
  35. } else {
  36. isSticky.value = false;
  37. }
  38. };
  39. onMounted(() => {
  40. window.addEventListener('scroll', handleScroll);
  41. });
  42. onUnmounted(() => {
  43. window.removeEventListener('scroll', handleScroll);
  44. });
  45. const menus = [
  46. { label: "Presentation" },
  47. { label: "Avantages" },
  48. { label: "Fonctionnalites" },
  49. { label: "Comparatif" },
  50. { label: "contact" },
  51. { label: "Temoignages" },
  52. { label: "formations" },
  53. { label: "Aide" },
  54. ];
  55. const activeMenu = ref(menus[0].label);
  56. const navigate = (menu) => {
  57. activeMenu.value = menu.label;
  58. const element = document.getElementById(menu.label);
  59. if (element) {
  60. element.scrollIntoView({ behavior: "smooth" });
  61. }
  62. };
  63. </script>
  64. <style scoped>
  65. .sticky-menu {
  66. position: fixed;
  67. top: 0;
  68. left: 0;
  69. right: 0;
  70. background: white;
  71. box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
  72. }
  73. .menu-container {
  74. z-index: 1000;
  75. display: flex;
  76. justify-content: space-around;
  77. padding: 1rem 10rem;
  78. background: white;
  79. color: #bbb8b8;
  80. font-family: "Barlow";
  81. font-size: 12px;
  82. line-height: 16px;
  83. display: flex;
  84. align-items: center;
  85. text-align: center;
  86. letter-spacing: 0.18em;
  87. text-transform: uppercase;
  88. border-bottom: 0.1rem solid #eaeaea;
  89. }
  90. .v-chip.active-menu {
  91. background: black;
  92. color: white;
  93. }
  94. .menu-container div:hover {
  95. cursor: pointer;
  96. text-decoration: underline;
  97. }
  98. </style>