lgSwiper.vue 3.0 KB

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