You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
3.7 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <section :class="['tw-relative tw-mt-[48px] xl:tw-max-w-[1246px] xl:tw-mx-auto']">
  3. <div class="swiper-container centerMode xl:tw-max-w-[1106px] xl:tw-mx-auto xl:tw-px-[22px]" ref="centerMode"
  4. @mouseenter="enter" @mouseleave="leave">
  5. <div :class="['swiper-wrapper']">
  6. <div v-for="(item, index) in list" :key="index" :class="['swiper-slide']">
  7. <a :href="item.url" :target="item.id == 'banner_1' ? '_self' : '_blank'">
  8. <div class="tw-rounded-[24px]">
  9. <lazyImg :src="item.image" :customClass="'swiper-lazy tw-rounded-[24px]'"></lazyImg>
  10. </div>
  11. </a>
  12. </div>
  13. </div>
  14. </div>
  15. <div :class="[
  16. 'swiper-button-prev ad tw-text-black tw-hidden',
  17. centerModeSwiper ? 'xl:tw-block' : '',
  18. ]"></div>
  19. <div :class="[
  20. 'swiper-button-next ad tw-text-black tw-hidden',
  21. centerModeSwiper ? 'xl:tw-block' : '',
  22. ]"></div>
  23. </section>
  24. </template>
  25. <script>
  26. import Swiper from "swiper/bundle";
  27. import lazyImg from "@/components/img/img.vue";
  28. export default {
  29. components: {
  30. Swiper,
  31. lazyImg,
  32. },
  33. props: {
  34. list: {
  35. type: Array,
  36. },
  37. },
  38. data() {
  39. return {
  40. centerModeSwiper: null,
  41. };
  42. },
  43. mounted() {
  44. let vm = this;
  45. vm.$nextTick(function () {
  46. vm.centerModeSwiper = new Swiper(".swiper-container.centerMode", {
  47. direction: "horizontal",
  48. initialSlide: 0,
  49. slidesPerView: 1.6,
  50. centeredSlides: true,
  51. loop: false,
  52. loopedSlides: 0,
  53. observer: true, //修改swiper自己或子元素时,自动初始化swiper
  54. observeParents: true, //修改swiper的父元素时,自动初始化swiper
  55. spaceBetween: 32,
  56. // autoplay: {
  57. // disableOnInteraction: true,
  58. // delay: 5000,
  59. // },
  60. preloadImages: false,
  61. lazy: {
  62. loadPrevNext: true,
  63. loadOnTransitionStart: true,
  64. loadPrevNextAmount: 6,
  65. },
  66. watchSlidesProgress: true,
  67. navigation: {
  68. nextEl: ".swiper-button-next.ad",
  69. prevEl: ".swiper-button-prev.ad",
  70. },
  71. breakpoints: {
  72. 414: {
  73. slidesPerView: 1.74,
  74. spaceBetween: 32,
  75. },
  76. 768: {
  77. slidesPerView: 1.74,
  78. spaceBetween: 48,
  79. },
  80. 1366: {
  81. slidesPerView: 3,
  82. spaceBetween: 24,
  83. centeredSlides: false,
  84. grabCursor: true,
  85. },
  86. },
  87. });
  88. vm.centerModeSwiper.init();
  89. vm.centerModeSwiper.update();
  90. });
  91. },
  92. methods: {
  93. enter() {
  94. this.centerModeSwiper.autoplay.stop();
  95. },
  96. leave() {
  97. this.centerModeSwiper.autoplay.start();
  98. },
  99. },
  100. };
  101. </script>
  102. <style lang="scss" scoped>
  103. .swiper-container {
  104. width: 100% !important;
  105. }
  106. .swiper-slide {
  107. margin-right: 20px;
  108. }
  109. .swiper-button {
  110. &-prev.ad {
  111. z-index: 4;
  112. &:focus-visible,
  113. &:focus {
  114. outline: none;
  115. }
  116. &::after {
  117. text-align: center;
  118. color: transparent;
  119. background-image: url('~/assets/svg/u-angle-left-b.svg');
  120. background-position: center;
  121. background-repeat: no-repeat;
  122. background-size: cover;
  123. }
  124. }
  125. &-next.ad {
  126. z-index: 4;
  127. &:focus-visible,
  128. &:focus {
  129. outline: none;
  130. }
  131. &::after {
  132. text-align: center;
  133. color: transparent;
  134. background-image: url('~/assets/svg/u-angle-right-b.svg');
  135. background-position: center;
  136. background-repeat: no-repeat;
  137. background-size: cover;
  138. }
  139. }
  140. }
  141. .active {
  142. position: relative;
  143. &::after {
  144. content: "";
  145. display: block;
  146. position: absolute;
  147. bottom: -12px;
  148. width: 100%;
  149. height: 2px;
  150. background-color: #f48800;
  151. }
  152. }
  153. </style>