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.

170 lines
4.4 KiB

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">
  3. <div class="swiper-container partnerWrapper xl:tw-max-w-[1060px] xl:tw-mx-auto">
  4. <div ref="partnerWrapper"
  5. class="swiper-wrapper tw-grid tw-grid-cols-2 tw-gap-x-[40px] tw-gap-y-[20px] md:tw-grid-cols-3 md:tw-gap-x-[36px] md:tw-gap-y-[19px] xl:tw-flex xl:tw-gap-0 xl:tw-grid-cols-none">
  6. <div
  7. class="swiper-slide partner tw-w-full xl:tw-flex xl:tw-justify-center xl:tw-items-center xl:tw-basis-1/5 xl:tw-max-w-[180px]"
  8. v-for="(item, index) in partnershiplist" :key="index">
  9. <img :src="item.image" />
  10. </div>
  11. </div>
  12. </div>
  13. <div class="swiper-button-prev partner tw-hidden xl:tw-block tw-h-[20px] tw-w-[12px]"></div>
  14. <div class="swiper-button-next partner tw-hidden xl:tw-block"></div>
  15. </section>
  16. </template>
  17. <script>
  18. import Swiper from "swiper";
  19. export default {
  20. data() {
  21. return {
  22. partnerSwiper: null,
  23. windewWidth: 0,
  24. };
  25. },
  26. components: { Swiper },
  27. props: {
  28. partnershiplist: {
  29. type: Array,
  30. },
  31. },
  32. created() {
  33. if (process.browser) {
  34. window.addEventListener("resize", this.handleResize);
  35. }
  36. this.handleResize();
  37. },
  38. mounted() {
  39. let vm = this;
  40. vm.$nextTick(function () {
  41. if (vm.windewWidth >= 1366) {
  42. vm.partnerSwiper = new Swiper(".swiper-container.partnerWrapper", {
  43. direction: "horizontal",
  44. initialSlide: 0,
  45. slidesPerView: 5,
  46. // centerInsufficientSlides: true,
  47. loop: true,
  48. loopedSlides: 0,
  49. autoplay: {
  50. disableOnInteraction: true,
  51. delay: 4000,
  52. },
  53. slidesPerGroup: 5,
  54. spaceBetween: 40,
  55. observer: true, //修改swiper自己或子元素时,自动初始化swiper
  56. observeParents: true, //修改swiper的父元素时,自动初始化swiper
  57. navigation: {
  58. nextEl: ".swiper-button-next.partner",
  59. prevEl: ".swiper-button-prev.partner",
  60. },
  61. });
  62. vm.partnerSwiper.init();
  63. vm.partnerSwiper.update();
  64. // vm.partnerSwiper.lazy.load();
  65. }
  66. })
  67. },
  68. destroyed() {
  69. if (process.browser) {
  70. window.removeEventListener("resize", this.handleResize);
  71. }
  72. },
  73. watch: {
  74. windewWidth: {
  75. handler: function () {
  76. let vm = this;
  77. if (vm.windewWidth >= 1366) {
  78. vm.partnerSwiper = new Swiper(".swiper-container.partnerWrapper", {
  79. direction: "horizontal",
  80. initialSlide: 0,
  81. slidesPerView: 5,
  82. // centerInsufficientSlides: true,
  83. loop: true,
  84. loopedSlides: 0,
  85. autoplay: {
  86. disableOnInteraction: true,
  87. delay: 4000,
  88. },
  89. slidesPerGroup: 5,
  90. spaceBetween: 40,
  91. observer: true, //修改swiper自己或子元素时,自动初始化swiper
  92. observeParents: true, //修改swiper的父元素时,自动初始化swiper
  93. navigation: {
  94. nextEl: ".swiper-button-next.partner",
  95. prevEl: ".swiper-button-prev.partner",
  96. },
  97. });
  98. vm.partnerSwiper.init();
  99. vm.partnerSwiper.update();
  100. } else {
  101. if (this.partnerSwiper) {
  102. this.partnerSwiper.destroy(false);
  103. setTimeout(function () {
  104. vm.$refs.partnerWrapper.removeAttribute('style');
  105. }, 1000)
  106. }
  107. }
  108. },
  109. },
  110. },
  111. methods: {
  112. handleResize() {
  113. if (process.browser) {
  114. this.windewWidth = window.innerWidth;
  115. }
  116. },
  117. },
  118. };
  119. </script>
  120. <style lang="scss" scoped>
  121. .swiper-button {
  122. &-prev.partner {
  123. color: transparent;
  124. z-index: 4;
  125. width: 12px !important;
  126. height: 20px !important;
  127. &:after {
  128. background-image: url("~/assets/svg/swiperarrowleft.svg");
  129. background-position: center;
  130. background-repeat: no-repeat;
  131. // background-size: 100%;
  132. width: 12px !important;
  133. height: 20px !important;
  134. }
  135. &:focus-visible,
  136. &:focus {
  137. outline: none;
  138. }
  139. }
  140. &-next.partner {
  141. color: transparent;
  142. width: 12px;
  143. height: 20px;
  144. z-index: 4;
  145. &:after {
  146. background-image: url("~/assets/svg/swiperarrowright.svg");
  147. background-position: center;
  148. background-repeat: no-repeat;
  149. // background-size: 100%;
  150. width: 12px;
  151. height: 20px;
  152. }
  153. &:focus-visible,
  154. &:focus {
  155. outline: none;
  156. }
  157. }
  158. }
  159. </style>