lgSwiper.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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">
  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. console.log(111)
  38. this.$emit('swiperClick', data);
  39. }
  40. },
  41. props: {
  42. sildeItems: {
  43. type: Array,
  44. required: true
  45. },
  46. image: {
  47. type: String,
  48. required: false,
  49. default: "image"
  50. },
  51. title: {
  52. type: String,
  53. required: false,
  54. default: "title"
  55. }
  56. },
  57. computed: {
  58. processedSildeItems() {
  59. return [...this.sildeItems, ...this.sildeItems];
  60. }
  61. }
  62. };
  63. </script>
  64. <style lang="scss" scoped>
  65. .container {
  66. display: flex;
  67. justify-content: center;
  68. align-items: center;
  69. }
  70. .swiper {
  71. width: 100%;
  72. overflow: visible;
  73. /* 确保部分滑块可见 */
  74. height: 100%;
  75. padding: 0 25rpx;
  76. }
  77. .swiper-item-active {
  78. z-index: 10;
  79. display: flex;
  80. align-items: center;
  81. .swiper-text {
  82. font-weight: bold;
  83. display: inline-block;
  84. // animation: marquee 10s linear infinite;
  85. /* 以下属性防止文字换行 */
  86. white-space: nowrap;
  87. }
  88. }
  89. @keyframes marquee {
  90. 0% {
  91. transform: translateX(20%);
  92. }
  93. 100% {
  94. transform: translateX(-100%);
  95. }
  96. }
  97. .swiper-item-normal {
  98. z-index: 1;
  99. display: flex;
  100. align-items: center;
  101. }
  102. .swiper-item {
  103. display: flex;
  104. height: 80%;
  105. width: 85%;
  106. margin: 0 auto;
  107. justify-content: flex-end;
  108. align-items: center;
  109. font-size: 16rpx;
  110. border-radius: 10px;
  111. flex-direction: column;
  112. color: #000;
  113. .swiper-text {
  114. white-space: nowrap;
  115. overflow: hidden;
  116. text-overflow: ellipsis;
  117. margin-top: 10rpx;
  118. }
  119. }
  120. .active {
  121. // display: flex;
  122. height: 100%;
  123. width: 93%;
  124. margin: auto;
  125. justify-content: center;
  126. font-size: 25rpx;
  127. .swiper-text {
  128. white-space: nowrap;
  129. overflow: hidden;
  130. text-overflow: ellipsis;
  131. }
  132. }
  133. </style>