Slider.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <!-- 滑块 -->
  3. <div class="slider">
  4. <!-- 标题部分 -->
  5. <div class="scienceTitle">
  6. <h5>三农科教</h5>
  7. <p class="title">
  8. <span v-for="(item, index) in scienceTitleList" :key="index" @mousemove="changeUl(index)">
  9. <a href="#">{{ item.title }}</a>
  10. </span>
  11. </p>
  12. </div>
  13. <!-- 标题下内容列表 -->
  14. <div class="box">
  15. <transition name="fade">
  16. <div class="scienceListBox">
  17. <ul class="scienceList">
  18. <li v-for="item in 6">
  19. <img src="../../static/images/sgbhsihfgisdfaasda45632113_A_Chinese_farmer_carrying_a_hoe_is_h_a23e4b96-a6d7-49e1-a283-68c395f277f9.png"
  20. alt="">
  21. <p>市农业农村局关于印发连云港市市级…</p>
  22. </li>
  23. </ul>
  24. <ul class="scienceList">
  25. <li v-for="item in 6">
  26. <img src="../../static/images/sgbhsihfgisdfaasda45632113_A_Chinese_farmer_carrying_a_hoe_is_h_1ba32eee-c498-4dd7-9cd9-013568c09db7.png"
  27. alt="">
  28. <p>市农业农村局关于印发连云港市市级…</p>
  29. </li>
  30. </ul>
  31. <ul class="scienceList">
  32. <li v-for="item in 6">
  33. <img src="../../static/images/rgmezdvz_19982_On_a_vast_and_boundless_wheat_field_many_harvest_5b5cfeda-ef17-4551-a935-5f8e3f799b69.png"
  34. alt="">
  35. <p>市农业农村局关于印发连云港市市级…</p>
  36. </li>
  37. </ul>
  38. <ul class="scienceList">
  39. <li v-for="item in 6">
  40. <img src="../../static/images/rgmezdvz_19982_A_Chinese_farmer_carrying_a_hoe_is_hoeing_the_fi_a036c7b3-b05e-4d3d-a371-0bed91ec1ff8(1).png"
  41. alt="">
  42. <p>市农业农村局关于印发连云港市市级…</p>
  43. </li>
  44. </ul>
  45. </div>
  46. </transition>
  47. </div>
  48. </div>
  49. </template>
  50. <script setup>
  51. let scienceTitleList = [
  52. {
  53. id: 1,
  54. title: "农产畅销"
  55. },
  56. {
  57. id: 2,
  58. title: "农业在线"
  59. },
  60. {
  61. id: 3,
  62. title: "农产行情"
  63. },
  64. {
  65. id: 4,
  66. title: "名优特产"
  67. }
  68. ]
  69. //鼠标移入标题时,下方内容会发生变化
  70. let changeUl = (index) => {
  71. // console.log(index);
  72. if (process.browser) {
  73. let scienceListBox = document.querySelector('.scienceListBox');
  74. let titleList = document.querySelectorAll('.title>span>a')
  75. for (let i = 0; i < titleList.length; i++) {
  76. titleList[i].className = ''
  77. }
  78. titleList[index].setAttribute('class', 'current')
  79. if (index == 0) {
  80. scienceListBox.style.left = 0
  81. } else if (index == 1) {
  82. scienceListBox.style.left = "-790px"
  83. } else if (index == 2) {
  84. scienceListBox.style.left = "-1580px"
  85. } else if (index == 3) {
  86. scienceListBox.style.left = "-2370px"
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="less" scoped>
  92. // 标题
  93. .scienceTitle {
  94. height: 37px;
  95. h5 {
  96. float: left;
  97. width: 96px;
  98. height: 34px;
  99. font-family: PingFang SC, PingFang SC;
  100. font-weight: 600;
  101. font-size: 24px;
  102. color: #000000;
  103. line-height: 28px;
  104. text-align: left;
  105. font-style: normal;
  106. text-transform: none;
  107. margin-right: 20px;
  108. }
  109. >p {
  110. float: left;
  111. height: 37px;
  112. line-height: 30px;
  113. >span {
  114. display: inline-block;
  115. height: 20px;
  116. line-height: 20px;
  117. text-align: center;
  118. margin: 4px 0px 3px;
  119. padding: 0 20px;
  120. border-right: 1px solid #ccc;
  121. >a {
  122. display: inline-block;
  123. padding-bottom: 11px;
  124. font-family: PingFang SC, PingFang SC;
  125. font-weight: 500;
  126. font-size: 20px;
  127. color: #666666;
  128. line-height: 20px;
  129. font-style: normal;
  130. text-transform: none;
  131. box-sizing: border-box;
  132. }
  133. .current {
  134. color: #139602;
  135. border-bottom: 1px solid #139602;
  136. }
  137. }
  138. >span:nth-child(4) {
  139. border-right: none;
  140. }
  141. >span:hover>a {
  142. color: #139602;
  143. border-bottom: 1px solid #139602;
  144. }
  145. }
  146. }
  147. .box {
  148. width: 790px;
  149. height: 570px;
  150. position: relative;
  151. overflow: hidden;
  152. }
  153. .fade-in{
  154. animation: fadeIn 1s ease-in-out;
  155. }
  156. .fade-enter-from,
  157. .fade-leave-to {
  158. opacity: 0;
  159. }
  160. .fade-enter-to,
  161. .fade-leave-from {
  162. opacity: 1;
  163. }
  164. .fade-enter-active,
  165. .fade-leave-active {
  166. transition: opacity 1s ease;
  167. }
  168. .scienceListBox {
  169. width: 3160px;
  170. height: 570px;
  171. position: absolute;
  172. top: 0;
  173. left: 0;
  174. transition: all 3s linear 0;
  175. }
  176. // 标题下列表
  177. .scienceList {
  178. width: 790px;
  179. height: 570px;
  180. float: left;
  181. margin-top: 17px;
  182. >li {
  183. width: 250px;
  184. height: 276px;
  185. float: left;
  186. margin-right: 20px;
  187. position: relative;
  188. >img {
  189. width: 250px;
  190. height: 220px;
  191. }
  192. >p {
  193. height: 56px;
  194. width: 248px;
  195. font-family: PingFang SC, PingFang SC;
  196. font-weight: 600;
  197. font-size: 18px;
  198. color: #333333;
  199. line-height: 24px;
  200. text-align: left;
  201. font-style: normal;
  202. text-transform: none;
  203. }
  204. >p:hover {
  205. color: #139602;
  206. }
  207. }
  208. >li:nth-child(3),
  209. >li:nth-child(6) {
  210. margin-right: 0;
  211. }
  212. >li::before {
  213. content: "";
  214. display: inline-block;
  215. width: 40px;
  216. height: 20px;
  217. position: absolute;
  218. top: 0;
  219. right: 0;
  220. background-image: url("../../static/images/Component 209.png");
  221. }
  222. }
  223. </style>