pageNavigation.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. <template>
  2. <div class="nav" :class="{ 'nav-fixed': isFixed }" ref="navRef">
  3. <div class="partOne">
  4. <div class="itemHome">
  5. <a href="/">首页</a>
  6. </div>
  7. <div class="itemContent">
  8. <div v-for="item in navList1" :key="item.name" class="item">
  9. <a :href="item.url">{{ item.name }}</a>
  10. </div>
  11. </div>
  12. </div>
  13. <div class="partTwo">
  14. <div class="itemHome">
  15. <a href="#">互动</a>
  16. </div>
  17. <div class="itemContent">
  18. <div v-for="item in navList2" :key="item.name" class="item">
  19. <a :href="item.url">{{ item.name }}</a>
  20. </div>
  21. </div>
  22. </div>
  23. <div class="partThree">
  24. <div class="itemHome">
  25. <a href="#">查询</a>
  26. </div>
  27. <div class="itemContent">
  28. <div v-for="item in navList3" :key="item.name" class="item">
  29. <a :href="item.url">{{ item.name }}</a>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. </template>
  35. <script setup>
  36. import { ref, onMounted, onUnmounted } from 'vue';
  37. // 1. 定义响应式状态:是否固定导航栏
  38. const isFixed = ref(false);
  39. // 2. 获取导航栏 DOM 引用
  40. const navRef = ref(null);
  41. // 3. 存储导航栏初始顶部位置
  42. let navOffsetTop = 0;
  43. // 滚动事件处理函数
  44. const handleScroll = () => {
  45. // 判断滚动距离是否超过导航栏初始位置
  46. isFixed.value = window.scrollY >= navOffsetTop;
  47. };
  48. onMounted(() => {
  49. // 组件挂载后,获取导航栏初始顶部位置
  50. navOffsetTop = navRef.value.offsetTop;
  51. // 监听滚动事件
  52. window.addEventListener('scroll', handleScroll);
  53. });
  54. onUnmounted(() => {
  55. // 组件卸载时移除监听,避免内存泄漏
  56. window.removeEventListener('scroll', handleScroll);
  57. });
  58. const navList1 = [
  59. {
  60. name: '法制资讯',
  61. url: '/sannongzixunzhifuxinxi/list-1.html'
  62. },
  63. {
  64. name: '各地动态',
  65. url: '/about'
  66. },
  67. {
  68. name: '特别关注',
  69. url: '/law'
  70. },
  71. {
  72. name: '媒体视点',
  73. url: '/case'
  74. },
  75. {
  76. name: '法纪通报',
  77. url: '/contact'
  78. },
  79. {
  80. name: '今日说法',
  81. url: '/contact'
  82. },
  83. {
  84. name: '政策法规',
  85. url: '/case'
  86. },
  87. {
  88. name: '政策解读',
  89. url: '/'
  90. },
  91. {
  92. name: '政务公开',
  93. url: '/about'
  94. },
  95. {
  96. name: '内参纪要',
  97. url: '/law'
  98. },
  99. {
  100. name: '执法在线',
  101. url: '/case'
  102. },
  103. {
  104. name: '法制监察',
  105. url: '/contact'
  106. },
  107. {
  108. name: '监督调查',
  109. url: '/contact'
  110. },
  111. {
  112. name: '社会调研',
  113. url: '/case'
  114. },
  115. {
  116. name: '典型案例',
  117. url: '/'
  118. },
  119. {
  120. name: '廉政时讯',
  121. url: '/about'
  122. },
  123. {
  124. name: '法制时评',
  125. url: '/law'
  126. },
  127. {
  128. name: '法制宣传',
  129. url: '/case'
  130. },
  131. {
  132. name: '百姓话题',
  133. url: '/contact'
  134. },
  135. {
  136. name: '投诉举报',
  137. url: '/contact'
  138. },
  139. {
  140. name: '经济与法',
  141. url: '/case'
  142. },
  143. {
  144. name: '法制建设',
  145. url: '/case'
  146. }
  147. ]
  148. const navList2 = [
  149. {
  150. name: '领导信箱',
  151. url: '/'
  152. },
  153. {
  154. name: '投诉举报',
  155. url: '/about'
  156. },
  157. {
  158. name: '网上政务',
  159. url: '/law'
  160. },
  161. {
  162. name: '志愿服务',
  163. url: '/case'
  164. },
  165. {
  166. name: '公益活动',
  167. url: '/contact'
  168. },
  169. {
  170. name: '在线服务',
  171. url: '/zaixianfuwu'
  172. },
  173. {
  174. name: '网民留言',
  175. url: '/wangminliuyan'
  176. },
  177. {
  178. name: '法制知识',
  179. url: '/'
  180. },
  181. {
  182. name: '法律咨询',
  183. url: '/falvzixun'
  184. },
  185. {
  186. name: '通知公告',
  187. url: '/law'
  188. },
  189. {
  190. name: '官网导航',
  191. url: '/guanwangdaohang'
  192. }
  193. ]
  194. const navList3 = [
  195. {
  196. name: '人员查询',
  197. url: '/'
  198. },
  199. {
  200. name: '车辆查询',
  201. url: '/about'
  202. },
  203. {
  204. name: '地市中心',
  205. url: '/law'
  206. },
  207. {
  208. name: '调研选题',
  209. url: '/case'
  210. },
  211. {
  212. name: '介绍信查询',
  213. url: '/contact'
  214. },
  215. {
  216. name: '核心网站',
  217. url: '/hexinwangzhan'
  218. },
  219. {
  220. name: '政务百网',
  221. url: '/zhengwubaiwang'
  222. },
  223. {
  224. name: '行业百网',
  225. url: '/hangyebaiwang'
  226. },
  227. {
  228. name: '规章制度',
  229. url: '/guizhangzhidu'
  230. },
  231. {
  232. name: '申请加入',
  233. url: '/shenqingjiaru'
  234. },
  235. {
  236. name: '项目官网',
  237. url: '/xiangmuguanwang'
  238. }
  239. ]
  240. </script>
  241. <style lang="less" scoped>
  242. // >1400px
  243. @media screen and (min-width: 1401px) {
  244. .nav {
  245. position: sticky; //粘性定位
  246. top: 0; //滚动到距离顶部0px时固定
  247. z-index: 9999; //保证固定时在其他内容上方
  248. width: 100%;
  249. font-family: "微软雅黑", "microsoft yahei";
  250. padding: 20PX 0;
  251. background: rgba(255, 255, 255, 0.8);
  252. box-sizing: border-box;
  253. .partOne {
  254. width: 1400PX;
  255. height: 70PX;
  256. background-color: #a60807;
  257. margin: 0 auto;
  258. display: flex;
  259. justify-content: center;
  260. align-items: center;
  261. .itemHome {
  262. width: 70PX;
  263. height: 70PX;
  264. line-height: 70PX;
  265. overflow: hidden;
  266. font-size: 16PX;
  267. color: #fff;
  268. font-weight: bold;
  269. text-align: center;
  270. a {
  271. font-size: 16PX;
  272. font-weight: bold;
  273. color: #fff;
  274. }
  275. }
  276. .itemContent {
  277. width: 1330PX;
  278. height: 70PX;
  279. line-height: 25PX;
  280. display: flex;
  281. flex-wrap: wrap;
  282. .item {
  283. width: 120PX;
  284. a {
  285. display: inline-block;
  286. width: 120PX;
  287. font-size: 16PX;
  288. font-weight: bold;
  289. color: #fff;
  290. text-align: center;
  291. &:hover {
  292. color: #FF8000;
  293. }
  294. }
  295. }
  296. }
  297. }
  298. .partTwo {
  299. width: 1400PX;
  300. height: 40PX;
  301. background-color: #c53729;
  302. margin: 0 auto;
  303. border-top: 4PX solid #fff;
  304. display: flex;
  305. justify-content: flex-start;
  306. align-items: center;
  307. .itemHome {
  308. width: 70PX;
  309. height: 40PX;
  310. line-height: 40PX;
  311. overflow: hidden;
  312. font-size: 16PX;
  313. color: #fff;
  314. font-weight: bold;
  315. text-align: center;
  316. a {
  317. font-size: 16PX;
  318. font-weight: bold;
  319. color: #fff;
  320. }
  321. }
  322. .itemContent {
  323. height: 40PX;
  324. line-height: 30PX;
  325. display: flex;
  326. flex-wrap: wrap;
  327. .item {
  328. width: 120PX;
  329. line-height: 30PX;
  330. a {
  331. display: inline-block;
  332. width: 120PX;
  333. font-size: 16PX;
  334. font-weight: bold;
  335. color: #fff;
  336. text-align: center;
  337. &:hover {
  338. color: #FF8000;
  339. }
  340. }
  341. }
  342. }
  343. }
  344. .partThree {
  345. width: 1400PX;
  346. height: 40PX;
  347. background-color: #d4ab73;
  348. margin: 0 auto;
  349. border-top: 4PX solid #fff;
  350. display: flex;
  351. flex-wrap: wrap;
  352. justify-content: flex-start;
  353. align-items: center;
  354. .itemHome {
  355. width: 70PX;
  356. height: 40PX;
  357. line-height: 40PX;
  358. overflow: hidden;
  359. font-size: 16PX;
  360. color: #fff;
  361. font-weight: bold;
  362. text-align: center;
  363. a {
  364. font-size: 16PX;
  365. font-weight: bold;
  366. color: #fff;
  367. }
  368. }
  369. .itemContent {
  370. height: 40PX;
  371. line-height: 30PX;
  372. display: flex;
  373. flex-wrap: wrap;
  374. .item {
  375. width: 120PX;
  376. line-height: 30PX;
  377. a {
  378. display: inline-block;
  379. width: 120PX;
  380. font-size: 16PX;
  381. font-weight: bold;
  382. color: #fff;
  383. text-align: center;
  384. &:hover {
  385. color: #FF8000;
  386. }
  387. }
  388. }
  389. }
  390. }
  391. }
  392. /* 固定在顶部时的样式 */
  393. .nav-fixed {
  394. position: fixed;
  395. top: 0;
  396. left: 0;
  397. background-color: #fff;
  398. }
  399. }
  400. // 800px-1400px
  401. @media (min-width: 801px) and (max-width: 1400px) {
  402. .nav {
  403. position: sticky !important; //粘性定位
  404. top: 0; //滚动到距离顶部0px时固定
  405. z-index: 1; //保证固定时在其他内容上方
  406. width: 100%;
  407. font-family: "微软雅黑", "microsoft yahei";
  408. .partOne {
  409. width: 100%;
  410. height: auto;
  411. background-color: #a60807;
  412. margin: 0 auto;
  413. display: flex;
  414. justify-content: center;
  415. align-items: center;
  416. .itemHome {
  417. width: 8%;
  418. overflow: hidden;
  419. font-size: 16PX;
  420. color: #fff;
  421. font-weight: bold;
  422. text-align: center;
  423. a {
  424. font-size: 16PX;
  425. font-weight: bold;
  426. color: #fff;
  427. }
  428. }
  429. .itemContent {
  430. width: 92%;
  431. line-height: 30PX;
  432. .item {
  433. width: 120PX;
  434. float: left;
  435. a {
  436. display: inline-block;
  437. width: 120PX;
  438. font-size: 16PX;
  439. font-weight: bold;
  440. color: #fff;
  441. text-align: center;
  442. &:hover {
  443. color: #FF8000;
  444. }
  445. }
  446. }
  447. }
  448. }
  449. .partTwo {
  450. width: 100%;
  451. height: auto;
  452. background-color: #c53729;
  453. margin: 0 auto;
  454. border-top: 4PX solid #fff;
  455. overflow: hidden;
  456. display: flex;
  457. justify-content: center;
  458. align-items: center;
  459. .itemHome {
  460. width: 8%;
  461. height: auto;
  462. overflow: hidden;
  463. font-size: 16PX;
  464. color: #fff;
  465. font-weight: bold;
  466. text-align: center;
  467. a {
  468. font-size: 16PX;
  469. font-weight: bold;
  470. color: #fff;
  471. }
  472. }
  473. .itemContent {
  474. width: 92%;
  475. line-height: 30PX;
  476. .item {
  477. width: 120PX;
  478. float: left;
  479. line-height: 30PX;
  480. a {
  481. display: inline-block;
  482. width: 120PX;
  483. font-size: 16PX;
  484. font-weight: bold;
  485. color: #fff;
  486. text-align: center;
  487. &:hover {
  488. color: #FF8000;
  489. }
  490. }
  491. }
  492. }
  493. }
  494. .partThree {
  495. width: 100%;
  496. height: auto;
  497. background-color: #d4ab73;
  498. margin: 0 auto;
  499. border-top: 4PX solid #fff;
  500. display: flex;
  501. justify-content: center;
  502. align-items: center;
  503. .itemHome {
  504. width: 8%;
  505. overflow: hidden;
  506. font-size: 16PX;
  507. color: #fff;
  508. font-weight: bold;
  509. text-align: center;
  510. a {
  511. font-size: 16PX;
  512. font-weight: bold;
  513. color: #fff;
  514. }
  515. }
  516. .itemContent {
  517. width: 92%;
  518. line-height: 30PX;
  519. .item {
  520. width: 120PX;
  521. float: left;
  522. line-height: 30PX;
  523. a {
  524. display: inline-block;
  525. width: 120PX;
  526. font-size: 16PX;
  527. font-weight: bold;
  528. color: #fff;
  529. text-align: center;
  530. &:hover {
  531. color: #FF8000;
  532. }
  533. }
  534. }
  535. }
  536. }
  537. }
  538. }
  539. // <=800px
  540. @media (max-width: 800px) {
  541. .nav {
  542. display: none;
  543. }
  544. }
  545. </style>