ThreeItemSwiper.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <view class="custom-swiper-wrapper">
  3. <swiper class="custom-swiper" :current="activeIndex" @change="onSwiperChange" circular :duration="300"
  4. indicator-dots="false" autoplay="false" display-multiple-items="1" :previous-margin="outerMargin"
  5. :next-margin="outerMargin" indicator-color="rgba(255, 255, 255, 0.5)" indicator-active-color="#FFEB66">
  6. <swiper-item v-for="(item, index) in products" :key="index">
  7. <view class="item-container">
  8. <view class="swiper-item" :class="{ 'swiper-item-active': index === currentCenterIndex }">
  9. <image class="item-image" :src="item.imgUrl" mode="aspectFit"></image>
  10. <view class="item-text" v-if="index === currentCenterIndex">
  11. <view class="text-title">{{ item.prizeLevel }}等奖</view>
  12. <view class="text-desc">{{ item.productName }}</view>
  13. </view>
  14. </view>
  15. </view>
  16. </swiper-item>
  17. </swiper>
  18. </view>
  19. </template>
  20. <script>
  21. import {
  22. string
  23. } from 'uview-plus/libs/function/test';
  24. export default {
  25. props: {
  26. products: {
  27. type: Array,
  28. default:() => [],
  29. }
  30. },
  31. data() {
  32. return {
  33. activeIndex: 0, // 初始激活项索引(建议从1开始,避免循环时偏移)
  34. outerMargin: '120rpx', // 轮播左右外部间距
  35. // swiperData: [{
  36. // image: "/static/images/zfb.png",
  37. // title: "二等奖",
  38. // desc: "纳美科学高浓度小苏打牙膏",
  39. // }
  40. // ],
  41. };
  42. },
  43. computed: {
  44. currentCenterIndex() {
  45. if (this.products.length === 0) return 0;
  46. return this.activeIndex % this.products.length;
  47. }
  48. },
  49. methods: {
  50. onSwiperChange(e) {
  51. this.activeIndex = e.detail.current;
  52. },
  53. },
  54. };
  55. </script>
  56. <style scoped>
  57. .custom-swiper-wrapper {
  58. width: 100%;
  59. overflow: hidden;
  60. }
  61. .custom-swiper {
  62. width: 100%;
  63. height: 500rpx;
  64. }
  65. .item-container {
  66. padding: 0 20rpx;
  67. }
  68. .swiper-item {
  69. width: 100% !important;
  70. height: 348rpx;
  71. background: #FFFFFF;
  72. box-shadow: 0rpx 12rpx 19rpx 2rpx rgba(219, 73, 22, 0.6);
  73. border-radius: 24rpx;
  74. border: 4rpx solid #FFCA96;
  75. display: flex;
  76. flex-direction: column;
  77. align-items: center;
  78. box-sizing: border-box;
  79. padding: 20rpx 0;
  80. transition: all 0.3s ease;
  81. }
  82. .swiper-item-active {
  83. transition: all 0.5s ease;
  84. height: 420rpx;
  85. z-index: 10;
  86. }
  87. .item-image {
  88. width: 280rpx;
  89. height: 280rpx;
  90. }
  91. .item-text {
  92. text-align: center;
  93. }
  94. .text-title {
  95. font-weight: 500;
  96. font-size: 32rpx;
  97. color: #222222;
  98. margin: 20rpx 0 10rpx;
  99. }
  100. .text-desc {
  101. font-size: 24rpx;
  102. color: #757575;
  103. }
  104. </style>