NavBar.vue 6.2 KB

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