lgSwiper.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view class="container">
  3. <swiper class="swiper" :circular="true" :autoplay="false" :duration="500" :previous-margin="'200rpx'"
  4. :next-margin="'200rpx'" :style="{ height: '320rpx' }" :current="currentIndex"
  5. :easing-function="easeInOutCubic" @change="changeCurrent">
  6. <swiper-item v-for="(slide, index) in processedSildeItems" :key="index" style="overflow: initial;"
  7. :class="index==currentIndex? 'swiper-item-active':'swiper-item-normal'" @click="swiperClick(slide)">
  8. <view :class="index==currentIndex? 'swiper-item active':'swiper-item'">
  9. <view style="width: 100%;height: 90%;position: relative;">
  10. <image style="width: 100%;height: 100%;" mode="aspectFit" :src="slide[image]"></image>
  11. <view style="background: linear-gradient(to bottom, rgb(255 248 248 / 86%), rgb(255 255 255 / 24%));
  12. position: absolute;z-index: 9999;width: 100%;height: 70rpx;"
  13. :class="index==currentIndex? 'end-active':'end'"
  14. v-if="slide.status === '2' || slide.status === '3'">
  15. <text style="font-size: 25rpx; padding-left:10rpx ;">已结束</text>
  16. </view>
  17. </view>
  18. <view class="swiper-text-box">
  19. <text class="swiper-text">{{ slide[title] }}</text>
  20. </view>
  21. </view>
  22. <!-- <view :class="index==currentIndex? 'swiper-item active':'swiper-item'" >
  23. <image style="width: 100%;height: 90%;" mode="aspectFit" :src="slide[image]" ></image>
  24. <text class="swiper-text">{{ slide[title] }}</text>
  25. </view> -->
  26. </swiper-item>
  27. </swiper>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. data() {
  33. return {
  34. currentIndex: 0
  35. };
  36. },
  37. methods: {
  38. changeCurrent(e) {
  39. this.currentIndex = e.detail.current
  40. },
  41. swiperClick(data) {
  42. // console.log(111, data)
  43. this.$emit('swiperClick', data);
  44. }
  45. },
  46. props: {
  47. sildeItems: {
  48. type: Array,
  49. required: true
  50. },
  51. image: {
  52. type: String,
  53. required: false,
  54. default: "image"
  55. },
  56. title: {
  57. type: String,
  58. required: false,
  59. default: "title"
  60. }
  61. },
  62. computed: {
  63. processedSildeItems() {
  64. return [...this.sildeItems, ...this.sildeItems];
  65. }
  66. }
  67. };
  68. </script>
  69. <style lang="scss" scoped>
  70. .container {
  71. display: flex;
  72. justify-content: center;
  73. align-items: center;
  74. }
  75. .swiper {
  76. width: 100%;
  77. overflow: visible;
  78. /* 确保部分滑块可见 */
  79. height: 100%;
  80. padding: 0 25rpx;
  81. }
  82. .swiper-item-active {
  83. z-index: 10;
  84. display: flex;
  85. align-items: center;
  86. .swiper-text {
  87. font-weight: bold;
  88. display: inline-block;
  89. // animation: marquee 10s linear infinite;
  90. /* 以下属性防止文字换行 */
  91. white-space: nowrap;
  92. }
  93. }
  94. .end-active{
  95. top: 0;
  96. // transform: translateY(-5%);
  97. left: 0;
  98. }
  99. .end{
  100. left: 15rpx;
  101. top: 0;
  102. }
  103. @keyframes marquee {
  104. 0% {
  105. transform: translateX(15%);
  106. }
  107. 100% {
  108. transform: translateX(-100%);
  109. }
  110. }
  111. .swiper-item-normal {
  112. z-index: 1;
  113. display: flex;
  114. align-items: center;
  115. }
  116. .swiper-item {
  117. display: flex;
  118. height: 70%;
  119. width: 85%;
  120. margin: 0 auto;
  121. justify-content: flex-end;
  122. align-items: center;
  123. font-size: 16rpx;
  124. border-radius: 10px;
  125. flex-direction: column;
  126. color: #000;
  127. .swiper-text {
  128. white-space: nowrap;
  129. overflow: hidden;
  130. text-overflow: ellipsis;
  131. // margin-top: 10rpx;
  132. margin-top: 7rpx;
  133. }
  134. .swiper-text-box {
  135. width: 100%;
  136. display: flex;
  137. justify-content: center;
  138. }
  139. }
  140. .active {
  141. // display: flex;
  142. height: 100%;
  143. width: 93%;
  144. margin: auto;
  145. justify-content: center;
  146. font-size: 25rpx;
  147. .swiper-text {
  148. white-space: nowrap;
  149. overflow: hidden;
  150. text-overflow: ellipsis;
  151. margin-top: 5rpx;
  152. }
  153. .swiper-text-box {
  154. width: auto;
  155. display: flex;
  156. justify-content: center;
  157. }
  158. }
  159. </style>