vear-carousel.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <swiper class="image-container" previous-margin="45rpx" next-margin="45rpx" 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: 350rpx;
  46. }
  47. .item-img {
  48. width: 630rpx;
  49. height: 300rpx;
  50. border-radius: 14rpx;
  51. animation: to-big .3s;
  52. }
  53. .swiper-item {
  54. width: 630rpx;
  55. height: 300rpx;
  56. display: flex;
  57. justify-content: center;
  58. align-items: center;
  59. }
  60. .item-img-side {
  61. width: 630rpx;
  62. height: 260rpx;
  63. border-radius: 14rpx;
  64. animation: to-mini .3s;
  65. }
  66. .swiper-item-side {
  67. width: 630rpx;
  68. height: 260rpx;
  69. display: flex;
  70. justify-content: center;
  71. align-items: center;
  72. }
  73. @keyframes to-mini
  74. {
  75. from {
  76. height: 300rpx;
  77. }
  78. to {
  79. height: 260rpx;
  80. }
  81. }
  82. @keyframes to-big
  83. {
  84. from {
  85. height: 260rpx;
  86. }
  87. to {
  88. height: 300rpx;
  89. }
  90. }
  91. </style>