index.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <swiper class="image-container" previous-margin="45rpx" next-margin="45rpx" circular autoplay
  3. @change="swiperChange">
  4. <swiper-item :class="currentIndex == index ? 'swiper-item' : 'swiper-item-side'"
  5. v-for="(item, index) in imgList" :key="item[urlKey]">
  6. <image @click="clickImg(item)" :class="currentIndex == index ? 'item-img' : 'item-img-side'"
  7. :src="item[urlKey]" lazy-load :style="dontFirstAnimation ? 'animation: none;' : ''" mode="aspectFill">
  8. </image>
  9. </swiper-item>
  10. </swiper>
  11. </template>
  12. <script>
  13. export default {
  14. props: {
  15. imgList: {
  16. type: Array,
  17. default () {
  18. return []
  19. }
  20. },
  21. urlKey: {
  22. type: String,
  23. default () {
  24. return ''
  25. }
  26. },
  27. },
  28. data() {
  29. return {
  30. currentIndex: 0,
  31. dontFirstAnimation: true
  32. }
  33. },
  34. methods: {
  35. swiperChange(e) {
  36. this.dontFirstAnimation = false
  37. this.currentIndex = e.detail.current
  38. },
  39. clickImg(item) {
  40. this.$emit('selected', item, this.currentIndex)
  41. }
  42. }
  43. }
  44. </script>
  45. <style scoped>
  46. .image-container {
  47. width: 750rpx;
  48. height: 350rpx;
  49. }
  50. .item-img {
  51. width: 630rpx;
  52. height: 300rpx;
  53. border-radius: 14rpx;
  54. animation: to-big .3s;
  55. }
  56. .swiper-item {
  57. width: 630rpx;
  58. height: 300rpx;
  59. display: flex;
  60. justify-content: center;
  61. align-items: center;
  62. }
  63. .item-img-side {
  64. width: 630rpx;
  65. height: 260rpx;
  66. border-radius: 14rpx;
  67. animation: to-mini .3s;
  68. }
  69. .swiper-item-side {
  70. width: 630rpx;
  71. height: 260rpx;
  72. display: flex;
  73. justify-content: center;
  74. align-items: center;
  75. }
  76. @keyframes to-mini {
  77. from {
  78. height: 300rpx;
  79. }
  80. to {
  81. height: 260rpx;
  82. }
  83. }
  84. @keyframes to-big {
  85. from {
  86. height: 260rpx;
  87. }
  88. to {
  89. height: 300rpx;
  90. }
  91. }
  92. </style>