lgSwiper.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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: '400rpx' }" :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'">
  9. <view :class="index==currentIndex? 'swiper-item active':'swiper-item'">
  10. <image style="width: 100%;height: 70%;" mode="aspectFill" :src="slide.tupian"></image>
  11. <text class="swiper-text">{{ slide.biaoti }}</text>
  12. </view>
  13. </swiper-item>
  14. </swiper>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. currentIndex: 0
  22. };
  23. },
  24. methods: {
  25. changeCurrent(e) {
  26. this.currentIndex = e.detail.current
  27. }
  28. },
  29. props: {
  30. sildeItems: {
  31. type: Array,
  32. required: true
  33. }
  34. },
  35. computed: {
  36. processedSildeItems() {
  37. return [...this.sildeItems, ...this.sildeItems];
  38. }
  39. }
  40. };
  41. </script>
  42. <style lang="scss" scoped>
  43. .container {
  44. display: flex;
  45. justify-content: center;
  46. align-items: center;
  47. }
  48. .swiper {
  49. width: 100%;
  50. overflow: visible;
  51. /* 确保部分滑块可见 */
  52. height: 100%;
  53. padding: 0 25rpx;
  54. }
  55. .swiper-item-active {
  56. z-index: 10;
  57. }
  58. .swiper-item-normal {
  59. z-index: 1;
  60. }
  61. .swiper-item {
  62. display: flex;
  63. height: 80%;
  64. width: 85%;
  65. margin: 0 auto;
  66. justify-content: flex-end;
  67. align-items: center;
  68. font-size: 14rpx;
  69. border-radius: 10px;
  70. flex-direction: column;
  71. color: #000;
  72. .swiper-text {
  73. white-space: nowrap;
  74. overflow: hidden;
  75. text-overflow: ellipsis;
  76. margin-top: 10rpx;
  77. }
  78. }
  79. .active {
  80. // display: flex;
  81. height: 100%;
  82. width: 93%;
  83. margin: auto;
  84. justify-content: center;
  85. // align-items: center;
  86. font-size: 24rpx;
  87. // border-radius: 10px;
  88. // flex-direction: column;
  89. .swiper-text {
  90. white-space: nowrap;
  91. overflow: hidden;
  92. text-overflow: ellipsis;
  93. }
  94. }
  95. </style>