NavBar.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <nav
  3. :class="[
  4. headerBlur ? 'need-blur' : '',
  5. scrollValue > 200 ? 'nav-scrolled' : 'nav-not-scrolled',
  6. ]"
  7. >
  8. <div class="group">
  9. <RouterLink to="/">首页</RouterLink>
  10. <RouterLink to="/news">资讯动态</RouterLink>
  11. <RouterLink to="/introduction">文化概况</RouterLink>
  12. <RouterLink to="/inheritor">保护传承</RouterLink>
  13. </div>
  14. <div class="group center">
  15. <div class="headerlogos">
  16. <img class="main-clickable" src="@/assets/images/LogoIcon.png" @click="goIndex" />
  17. <div>
  18. <p class="large">闽南文化生态保护区<span>(厦门市)</span></p>
  19. <p>Minnan Cultural Ecological Protection Area</p>
  20. </div>
  21. </div>
  22. </div>
  23. <div class="group">
  24. <RouterLink to="/communicate">传播交流</RouterLink>
  25. <RouterLink to="/research">理论研究</RouterLink>
  26. <RouterLink to="/fusion">文旅融合</RouterLink>
  27. <RouterLink to="/about">关于我们</RouterLink>
  28. </div>
  29. <!-- 移动端菜单 -->
  30. <div class="mobile-menu">
  31. <IconMenu
  32. :openState="mobileMenuShow"
  33. @click="mobileMenuShow = !mobileMenuShow"
  34. />
  35. <div
  36. :class="[
  37. 'mobile-menu-popover',
  38. mobileMenuShow ? 'visible' : '',
  39. ]"
  40. @click="mobileMenuShow=false"
  41. >
  42. <RouterLink to="/">首页</RouterLink>
  43. <RouterLink to="/news">资讯动态</RouterLink>
  44. <RouterLink to="/introduction">文化概况</RouterLink>
  45. <RouterLink to="/inheritor">保护传承</RouterLink>
  46. <RouterLink to="/communicate">传播交流</RouterLink>
  47. <RouterLink to="/research">理论研究</RouterLink>
  48. <RouterLink to="/fusion">文旅融合</RouterLink>
  49. <RouterLink to="/about">关于我们</RouterLink>
  50. </div>
  51. </div>
  52. </nav>
  53. </template>
  54. <script setup lang="ts">
  55. import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
  56. import { useRoute, useRouter } from 'vue-router';
  57. import IconMenu from './icons/IconMenu.vue';
  58. const router = useRouter();
  59. const route = useRoute();
  60. const scrollValue = ref(0);
  61. const mobileMenuShow = ref(false);
  62. const headerBlur = computed(() => {
  63. return route.name != 'home';
  64. });
  65. function goIndex() {
  66. router.push({ name: 'home' });
  67. }
  68. function onScroll() {
  69. scrollValue.value = window.scrollY;
  70. }
  71. onMounted(() => {
  72. window.addEventListener('scroll', onScroll);
  73. });
  74. onBeforeUnmount(() => {
  75. window.removeEventListener('scroll', onScroll);
  76. });
  77. </script>
  78. <style lang="scss">
  79. @use '@/assets/scss/colors.scss' as *;
  80. $nav-height: 70px;
  81. .nav-placeholder {
  82. height: $nav-height;
  83. background-color: $primary-color;
  84. }
  85. nav {
  86. position: fixed;
  87. display: flex;
  88. justify-content: space-around;
  89. align-items: center;
  90. z-index: 100;
  91. width: 100%;
  92. height: $nav-height;
  93. background-color: transparent;
  94. border-bottom: 1px solid rgba(#fff, 0.2);
  95. color: #fff;
  96. transition: all ease-in-out 0.3s;
  97. &.nav-scrolled {
  98. background-color: $primary-color;
  99. }
  100. &.need-blur.nav-not-scrolled {
  101. background-color: transparent;
  102. backdrop-filter: blur(10px);
  103. }
  104. a {
  105. color: rgba(#fff, 0.8);
  106. text-align: center;
  107. text-decoration: none;
  108. &:focus {
  109. outline: none;
  110. }
  111. &.router-link-active, &.router-link-exact-active, &:hover {
  112. color: #fff;
  113. }
  114. &.router-link-exact-active {
  115. font-weight: bold;
  116. }
  117. }
  118. .group {
  119. display: flex;
  120. gap: 1rem;
  121. a {
  122. width: 100px;
  123. height: $nav-height;
  124. line-height: $nav-height;
  125. }
  126. }
  127. .headerlogos {
  128. display: flex;
  129. flex-direction: row;
  130. align-items: center;
  131. img {
  132. width: 45px;
  133. height: 45px;
  134. margin-right: 10px;
  135. }
  136. > div {
  137. display: flex;
  138. flex-direction: column;
  139. justify-content: center;
  140. font-family: nzgrRuyinZouZhangKai;
  141. margin-bottom: 6px;
  142. p {
  143. margin: 0;
  144. font-size: 1rem;
  145. height: 20px;
  146. span {
  147. font-size: 1rem;
  148. margin-left: 10px;
  149. }
  150. &.large {
  151. height: 33px;
  152. font-size: 1.8rem;
  153. letter-spacing: -0.1rem;
  154. }
  155. }
  156. }
  157. }
  158. .mobile-menu {
  159. display: none;
  160. }
  161. .mobile-menu-popover {
  162. display: none;
  163. flex-direction: column;
  164. position: absolute;
  165. top: $nav-height;
  166. right: 0;
  167. left: 0;
  168. background-color: $box-color;
  169. border-bottom: $border-grey-color;
  170. color: $text-color;
  171. padding: 14px 0;
  172. animation: mobile-menu-popover-fade 0.3s ease-in-out;
  173. a {
  174. line-height: 40px;
  175. height: 40px;
  176. width: 100%;
  177. color: $text-color;
  178. }
  179. &.visible {
  180. display: flex;
  181. }
  182. }
  183. }
  184. @media (max-width: 1260px) {
  185. nav {
  186. .group {
  187. gap: 0.5rem;
  188. a {
  189. width: 80px;
  190. }
  191. }
  192. .headerlogos > div {
  193. display: none;
  194. }
  195. }
  196. }
  197. @media (max-width: 1024px) {
  198. }
  199. @media (max-width: 768px) {
  200. nav {
  201. justify-content: space-between;
  202. padding: 0 30px;
  203. .group:not(.center) {
  204. display: none;
  205. }
  206. .mobile-menu {
  207. display: block;
  208. }
  209. }
  210. }
  211. @keyframes mobile-menu-popover-fade {
  212. 0% { opacity: 0; transform: translateY(-10px); }
  213. 100% { opacity: 1; transform: translateY(0); }
  214. }
  215. </style>