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.

297 lines
6.4 KiB

2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div id="serviceSlideshow" :class="[
  3. 'swiper-container service md:tw-max-w-[1246px] md:tw-mx-auto',
  4. multipleBanner ? '' : 'tw-pointer-events-none',
  5. ]" ref="slideshow" @mouseenter="enter" @mouseleave="leave">
  6. <div class="swiper-wrapper">
  7. <div class="swiper-slide tw-max-h-[232px] tw-overflow-y-hidden md:tw-max-h-[300px] xl:tw-max-h-[540px]"
  8. v-for="item in banners" :key="item.banner_id">
  9. <!-- <img :data-src="item.image" class="swiper-lazy" /> -->
  10. <img :src="item.image" class="swiper-lazy" />
  11. </div>
  12. </div>
  13. <div class="swiper-pagination service"></div>
  14. <div class="swiper-button-prev service tw-hidden xl:tw-block"></div>
  15. <div class="swiper-button-next service tw-hidden xl:tw-block"></div>
  16. </div>
  17. </template>
  18. <script>
  19. import Swiper from "swiper/bundle";
  20. import lazyImg from "@/components/img/img.vue";
  21. export default {
  22. props: {
  23. banners: {
  24. type: Array,
  25. required: false,
  26. default: [],
  27. },
  28. },
  29. components: { Swiper, lazyImg },
  30. data() {
  31. return {
  32. slideshow: null,
  33. };
  34. },
  35. mounted() {
  36. let vm = this;
  37. vm.$nextTick(function () {
  38. if (vm.banners.length > 1) {
  39. vm.slideshow = new Swiper("#serviceSlideshow", {
  40. speed: 400,
  41. initialSlide: 0,
  42. autoHeight: false,
  43. direction: "horizontal",
  44. loop: true,
  45. autoplay: {
  46. delay: 5000,
  47. disableOnInteraction: true,
  48. waitForTransition: false,
  49. },
  50. preloadImages: false,
  51. lazy: {
  52. loadPrevNext: true,
  53. loadOnTransitionStart: true,
  54. loadPrevNextAmount: 6,
  55. },
  56. autoplayStopOnLast: false, // loop false also
  57. effect: "slide",
  58. slidesPerView: "auto",
  59. centeredSlides: true,
  60. loopedSlides: 0,
  61. slidesPerGroup: 1,
  62. slidesOffsetBefore: 0,
  63. grabCursor: true,
  64. pagination: {
  65. el: ".swiper-pagination.service",
  66. clickable: true,
  67. },
  68. navigation: {
  69. nextEl: ".swiper-button-next.service",
  70. prevEl: ".swiper-button-prev.service",
  71. },
  72. });
  73. } else {
  74. vm.slideshow = new Swiper("#serviceSlideshow", {
  75. speed: 400,
  76. initialSlide: 0,
  77. autoHeight: false,
  78. direction: "horizontal",
  79. loop: true,
  80. preloadImages: false,
  81. lazy: {
  82. loadPrevNext: true,
  83. loadOnTransitionStart: true,
  84. loadPrevNextAmount: 6,
  85. },
  86. autoplayStopOnLast: false, // loop false also
  87. effect: "slide",
  88. slidesPerView: "auto",
  89. centeredSlides: true,
  90. loopedSlides: 0,
  91. slidesPerGroup: 1,
  92. slidesOffsetBefore: 0,
  93. grabCursor: true,
  94. });
  95. }
  96. vm.slideshow.init();
  97. vm.slideshow.update();
  98. });
  99. },
  100. computed: {
  101. multipleBanner() {
  102. if (this.banners.length > 1) {
  103. return true;
  104. } else {
  105. return false;
  106. }
  107. },
  108. },
  109. methods: {
  110. enter() {
  111. if (this.banners.length > 1) {
  112. this.slideshow.autoplay.stop();
  113. }
  114. },
  115. leave() {
  116. if (this.banners.length > 1) {
  117. this.slideshow.autoplay.start();
  118. }
  119. },
  120. },
  121. };
  122. </script>
  123. <style lang="scss" scoped>
  124. .swiper-container.service:deep() {
  125. @media screen and (min-width: 768px) {
  126. padding: 0 100px;
  127. }
  128. @media screen and (min-width: 1366px) {
  129. padding: 0 143px;
  130. }
  131. }
  132. .swiper-container.service:hover:deep() {
  133. .swiper-button {
  134. &-prev {
  135. opacity: 1;
  136. transform: translateX(0);
  137. }
  138. &-next {
  139. opacity: 1;
  140. transform: translateX(0);
  141. }
  142. }
  143. }
  144. .swiper-container:deep() {
  145. .swiper-slide {
  146. width: 100% !important;
  147. @media screen and (min-width: 768px) {
  148. margin: 0 20px;
  149. max-height: 300px;
  150. overflow-y: hidden;
  151. }
  152. @media screen and (min-width: 1366px) {
  153. margin: 0 15px;
  154. max-height: 540px;
  155. }
  156. >img {
  157. width: 100%;
  158. height: auto;
  159. }
  160. }
  161. .swiper-slide-prev,
  162. .swiper-slide-next {
  163. transition: all 0.5s linear;
  164. filter: opacity(0.5);
  165. }
  166. .swiper-button {
  167. &-prev {
  168. color: transparent;
  169. top: 60%;
  170. left: 40px;
  171. width: 20px;
  172. height: 20px;
  173. opacity: 0;
  174. transform: translateX(-10px);
  175. transition: all 0.3s linear;
  176. &:after {
  177. display: block;
  178. background-image: url("~/assets/svg/Arrow-left.svg");
  179. background-position: center;
  180. background-repeat: no-repeat;
  181. background-size: 100%;
  182. width: 20px;
  183. height: 20px;
  184. }
  185. @media screen and (min-width: 768px) {
  186. top: 55%;
  187. left: 120px;
  188. width: 30px;
  189. height: 30px;
  190. &:after {
  191. width: 30px;
  192. height: 30px;
  193. }
  194. }
  195. @media screen and (min-width: 1366px) {
  196. top: 50%;
  197. left: 163px;
  198. width: 50px;
  199. height: 50px;
  200. &:after {
  201. width: 50px;
  202. height: 50px;
  203. }
  204. }
  205. }
  206. &-next {
  207. color: transparent;
  208. top: 60%;
  209. right: 40px;
  210. opacity: 0;
  211. width: 20px;
  212. height: 20px;
  213. transform: translateX(10px);
  214. transition: all 0.5s linear;
  215. &:after {
  216. display: block;
  217. background-image: url("~/assets/svg/Arrow-left.svg");
  218. background-position: center;
  219. background-repeat: no-repeat;
  220. background-size: 100%;
  221. transform: rotate(180deg);
  222. width: 20px;
  223. height: 20px;
  224. }
  225. @media screen and (min-width: 768px) {
  226. top: 55%;
  227. right: 120px;
  228. width: 30px;
  229. height: 30px;
  230. &:after {
  231. width: 30px;
  232. height: 30px;
  233. }
  234. }
  235. @media screen and (min-width: 1366px) {
  236. top: 50%;
  237. right: 163px;
  238. width: 50px;
  239. height: 50px;
  240. &:after {
  241. width: 50px;
  242. height: 50px;
  243. }
  244. }
  245. }
  246. }
  247. .swiper-pagination-bullets {
  248. @media screen and (min-width: 768px) {
  249. bottom: 20px;
  250. }
  251. }
  252. }
  253. .swiper-container:deep() {
  254. .swiper-pagination-bullet {
  255. opacity: 1;
  256. background-color: #fff6ee;
  257. width: 4px;
  258. height: 4px;
  259. @media screen and (min-width: 768px) {
  260. width: 8px;
  261. height: 8px;
  262. }
  263. @media screen and (min-width: 1366px) {
  264. width: 14px;
  265. height: 14px;
  266. }
  267. &-active {
  268. background-color: #f48800;
  269. }
  270. }
  271. }
  272. </style>