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.

143 lines
3.4 KiB

  1. <template>
  2. <section :class="['tw-relative xl:tw-max-w-[1246px] xl:tw-mx-auto']">
  3. <div class="swiper-container advertisementMode" ref="advertisementMode"
  4. @mouseenter="enter" @mouseleave="leave">
  5. <div :class="['swiper-wrapper']">
  6. <div v-for="(item, index) in advertisementList" :key="index" :class="['swiper-slide']">
  7. <a :href="localePath(`${item.url}`)" target="_self">
  8. <lazyImg :src="item.image" :customClass="'swiper-lazy'"></lazyImg>
  9. </a>
  10. </div>
  11. </div>
  12. <div class="swiper-pagination tw-hidden" slot="pagination"></div>
  13. </div>
  14. <!-- <div :class="[
  15. 'swiper-button-prev ad tw-text-black tw-hidden',
  16. advertisementSwiper ? 'xl:tw-block' : '',
  17. ]"></div>
  18. <div :class="[
  19. 'swiper-button-next ad tw-text-black tw-hidden',
  20. advertisementSwiper ? 'xl:tw-block' : '',
  21. ]"></div> -->
  22. </section>
  23. </template>
  24. <script>
  25. import Swiper from "swiper/bundle";
  26. import lazyImg from "@/components/img/img.vue";
  27. export default {
  28. components: {
  29. Swiper,
  30. lazyImg,
  31. },
  32. props: {
  33. advertisementList: {
  34. type: Array,
  35. },
  36. },
  37. data() {
  38. return {
  39. advertisementSwiper: null,
  40. };
  41. },
  42. mounted() {
  43. let vm = this;
  44. vm.$nextTick(function () {
  45. vm.advertisementSwiper = new Swiper(".swiper-container.advertisementMode", {
  46. direction: "horizontal",
  47. initialSlide: 1,
  48. centeredSlidesBounds: true,
  49. slidesPerView: 1,
  50. centeredSlides: true,
  51. loop: true,
  52. loopedSlides: 0,
  53. observer: true, //修改swiper自己或子元素时,自动初始化swiper
  54. observeParents: true, //修改swiper的父元素时,自动初始化swiper
  55. spaceBetween: 20,
  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. pagination:{
  72. el: ".swiper-pagination",
  73. clickable: true,
  74. },
  75. breakpoints: {
  76. 768: {
  77. slidesPerView: 1,
  78. spaceBetween: 20,
  79. },
  80. 1366: {
  81. slidesPerView: 1,
  82. spaceBetween: 20,
  83. centeredSlides: false,
  84. grabCursor: true,
  85. },
  86. },
  87. });
  88. vm.advertisementSwiper.init();
  89. vm.advertisementSwiper.update();
  90. });
  91. },
  92. methods: {
  93. enter() {
  94. this.advertisementSwiper.autoplay.stop();
  95. },
  96. leave() {
  97. this.advertisementSwiper.autoplay.start();
  98. },
  99. },
  100. };
  101. </script>
  102. <style>
  103. .swiper-container {
  104. width: 100% !important;
  105. }
  106. .pagination {
  107. position: absolute;
  108. z-index: 20;
  109. bottom: 10px;
  110. width: 100%;
  111. text-align: center;
  112. }
  113. .swiper-pagination-switch {
  114. display: inline-block;
  115. width: 12px;
  116. height: 12px;
  117. /* border-radius: 16px; */
  118. background: #c1c3c2;
  119. margin: 0 15px;
  120. /* opacity: 0.8; */
  121. border: 1px solid #c1c3c2;
  122. cursor: pointer;
  123. }
  124. .swiper-active-switch {
  125. background: #d38217;
  126. }
  127. .swiper-pagination-bullet {
  128. background-color: #c1c3c2;
  129. width: 12px;
  130. height: 12px;
  131. border-radius: 12px;
  132. opacity: 1;
  133. }
  134. .swiper-pagination-bullet-active{
  135. background-color: #d38217;
  136. width: 12px;
  137. height: 12px;
  138. border-radius: 12px;
  139. }
  140. </style>