lgSwiper.vue 3.7 KB

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