vear-carousel.vue 1.7 KB

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