index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <view class="demo-swiper">
  3. <demo-block title="自定义">
  4. <z-swiper ref="zSwiper" v-model="list" @slideChange="onChange">
  5. <z-swiper-item v-for="(item,index) in list" :key="index">
  6. <demo-item :item="item"></demo-item>
  7. </z-swiper-item>
  8. <template #indicator>
  9. <view class="custom-indicator">{{ current + 1 }}/{{list.length}}</view>
  10. </template>
  11. </z-swiper>
  12. <z-swiper :custom-style="{'margin-top':'20rpx'}" ref="zSwiper1" v-model="list" @slideChange="onChange1">
  13. <z-swiper-item v-for="(item,index) in list" :key="index">
  14. <demo-item :item="item"></demo-item>
  15. </z-swiper-item>
  16. <template #indicator>
  17. <view class="custom-indicator-list">
  18. <view :class="['custom-indicator-list-item',index == current1?'custom-indicator-list-item-active':'']"
  19. v-for="(item,index) in list" :key="index" @click="changSwiper(index)">
  20. {{index+1}}
  21. </view>
  22. </view>
  23. </template>
  24. </z-swiper>
  25. <z-swiper :custom-style="{'margin-top':'20rpx'}" ref="zSwiper2" v-model="list" @slideChange="onChange2">
  26. <z-swiper-item v-for="(item,index) in list" :key="index">
  27. <demo-item :item="item"></demo-item>
  28. </z-swiper-item>
  29. <template #indicator>
  30. <view class="custom-indicator-list1">
  31. <view :class="['custom-indicator-list-item1',index == current2?'custom-indicator-list-item1-active':'']"
  32. v-for="(item,index) in list" :key="index">
  33. </view>
  34. </view>
  35. </template>
  36. </z-swiper>
  37. <z-swiper :custom-style="{'margin-top':'20rpx'}" ref="zSwiper3" v-model="list" @slideChange="onChange3">
  38. <z-swiper-item v-for="(item,index) in list" :key="index">
  39. <demo-item :item="item"></demo-item>
  40. </z-swiper-item>
  41. <template #indicator>
  42. <view class="custom-indicator-list2">
  43. <template v-for="(item,index) in list">
  44. <view :key="index" v-if="index == current3 - 2"
  45. class="custom-indicator-list2-bullet custom-indicator-list2-bullet-prev-prev">
  46. </view>
  47. <view :key="index" v-else-if="index == current3 - 1"
  48. class="custom-indicator-list2-bullet custom-indicator-list2-bullet-prev">
  49. </view>
  50. <view :key="index" v-else-if="index == current3"
  51. class="custom-indicator-list2-bullet custom-indicator-list2-bullet-active">
  52. </view>
  53. <view :key="index" v-else-if="index == current3 + 1"
  54. class="custom-indicator-list2-bullet custom-indicator-list2-bullet-next">
  55. </view>
  56. <view :key="index" v-else-if="index == current3 + 2"
  57. class="custom-indicator-list2-bullet custom-indicator-list2-bullet-next-next">
  58. </view>
  59. </template>
  60. </view>
  61. </template>
  62. </z-swiper>
  63. </demo-block>
  64. </view>
  65. </template>
  66. <script>
  67. import data from '../../common/js/data.js'
  68. export default {
  69. data() {
  70. return {
  71. current: 0,
  72. current1: 0,
  73. current2: 0,
  74. current3: 0,
  75. list: data,
  76. }
  77. },
  78. methods: {
  79. onChange() {
  80. this.current = this.$refs.zSwiper.swiper.activeIndex;
  81. },
  82. onChange1() {
  83. this.current1 = this.$refs.zSwiper1.swiper.activeIndex;
  84. },
  85. onChange2() {
  86. this.current2 = this.$refs.zSwiper2.swiper.activeIndex;
  87. },
  88. onChange3() {
  89. this.current3 = this.$refs.zSwiper3.swiper.activeIndex;
  90. },
  91. changSwiper(index) {
  92. if (index != this.current1) {
  93. this.$refs.zSwiper1.swiper.slideTo(index, 300, false);
  94. }
  95. },
  96. }
  97. }
  98. </script>
  99. <style scoped lang="scss">
  100. .demo-swiper {
  101. .custom-indicator {
  102. position: absolute;
  103. right: 30rpx;
  104. bottom: 30rpx;
  105. padding: 4rpx 10rpx;
  106. font-size: 24rpx;
  107. color: #FFFFFF;
  108. background: rgba(0, 0, 0, 0.1);
  109. z-index: 10;
  110. }
  111. .custom-indicator-list {
  112. position: absolute;
  113. bottom: 30rpx;
  114. left: 0;
  115. width: 100%;
  116. display: flex;
  117. align-items: center;
  118. justify-content: center;
  119. z-index: 10;
  120. .custom-indicator-list-item {
  121. width: 40rpx;
  122. height: 40rpx;
  123. text-align: center;
  124. line-height: 40rpx;
  125. font-size: 24rpx;
  126. color: #000;
  127. opacity: 1;
  128. background: rgba(0, 0, 0, 0.2);
  129. border-radius: 50%;
  130. margin: 0 8rpx;
  131. &-active {
  132. color: #fff;
  133. background: #007aff;
  134. }
  135. }
  136. }
  137. .custom-indicator-list1 {
  138. position: absolute;
  139. bottom: 30rpx;
  140. left: 0;
  141. width: 100%;
  142. display: flex;
  143. align-items: center;
  144. justify-content: center;
  145. z-index: 10;
  146. .custom-indicator-list-item1 {
  147. margin: 0 5rpx;
  148. background-color: #e8f5ff;
  149. width: 20rpx;
  150. height: 10rpx;
  151. opacity: 1;
  152. border-radius: 5rpx;
  153. transition: opacity .3s, background-color .3s, width .3s;
  154. &-active {
  155. background-color: #3eb2f3;
  156. width: 35rpx;
  157. }
  158. }
  159. }
  160. .custom-indicator-list2 {
  161. position: absolute;
  162. bottom: 30rpx;
  163. left: 0;
  164. width: 100%;
  165. display: flex;
  166. align-items: center;
  167. justify-content: center;
  168. z-index: 10;
  169. .custom-indicator-list2-bullet {
  170. margin: 0 8rpx;
  171. position: relative;
  172. width: 16rpx;
  173. height: 16rpx;
  174. border-radius: 50%;
  175. background-color: #e8f5ff;
  176. opacity: 1;
  177. transition: .2s width, .2s height, .2s background-color, .2s opacity, .2s transform;
  178. &-active {
  179. transform: scale(1);
  180. opacity: 1;
  181. background-color: #3eb2f3;
  182. }
  183. &-prev {
  184. transform: scale(.66);
  185. }
  186. &-prev-prev {
  187. transform: scale(.33);
  188. }
  189. &-next {
  190. transform: scale(.66);
  191. }
  192. &-next-next {
  193. transform: scale(.33);
  194. }
  195. }
  196. }
  197. }
  198. </style>