graceSwiperCard.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <view>
  3. <swiper :style="{width:width, height:height}" class="grace-swiper-card"
  4. :indicator-dots="indicatorDots" :interval="interval"
  5. :indicator-color="indicatorColor" :indicator-active-color="indicatorActiveColor"
  6. :duration="500" :circular="true" :autoplay="autoplay" :current="currentIndex"
  7. :previous-margin="spacing" :next-margin="spacing" @change="swiperchange">
  8. <swiper-item v-for="(item, index) in swiperItems" :key="index" class="grace-swiper-card-item">
  9. <navigator :url="item.url" :open-type="item.opentype" hover-class="none" :style="{padding :padding}">
  10. <image :style="{borderRadius : borderRadius}"
  11. :src="item.img" class="grace-swiper-card-image"
  12. :class="[
  13. current != index && scale ? 'grace-swiper-card-img-small' : '',
  14. current == index && isReady ? 'grace-swiper-card-img-big' : ''
  15. ]" mode="widthFix" />
  16. </navigator>
  17. </swiper-item>
  18. </swiper>
  19. </view>
  20. </template>
  21. <script>
  22. export default{
  23. props:{
  24. width:{
  25. type : String,
  26. default : "100%"
  27. },
  28. height:{
  29. type : String,
  30. default : "300rpx"
  31. },
  32. swiperItems : {
  33. type : Array,
  34. default : function(){return new Array();}
  35. },
  36. borderRadius : {
  37. type : String,
  38. default : '5rpx'
  39. },
  40. indicatorColor : {
  41. type : String,
  42. default : "rgba(0, 0, 0, 0.2)"
  43. },
  44. indicatorActiveColor : {
  45. type : String,
  46. default : "#3688FF"
  47. },
  48. spacing : {
  49. type : String,
  50. default : "50rpx"
  51. },
  52. interval : {
  53. type : Number,
  54. default : 5000
  55. },
  56. padding:{
  57. type : String,
  58. default : '0 10rpx'
  59. },
  60. scale : {
  61. type : Boolean,
  62. default : true
  63. },
  64. autoplay : {
  65. type : Boolean,
  66. default : true
  67. },
  68. currentIndex : {
  69. type : Number,
  70. default : 0
  71. },
  72. indicatorDots:{
  73. type : Boolean,
  74. default:true
  75. }
  76. },
  77. data() {
  78. return {
  79. current : 0,
  80. isReady : false
  81. }
  82. },
  83. watch:{
  84. currentIndex : function (val) {
  85. this.current = val;
  86. }
  87. },
  88. created:function(){
  89. this.current = this.currentIndex;
  90. },
  91. methods:{
  92. swiperchange : function (e) {
  93. this.current = e.detail.current;
  94. this.$emit('swiperchange', this.current);
  95. this.isReady = true;
  96. }
  97. }
  98. }
  99. </script>
  100. <style scoped>
  101. .grace-swiper-card-item{box-sizing: border-box; font-size:0; overflow:hidden;}
  102. .grace-swiper-card-image{width:100%;}
  103. .grace-swiper-card-img-small{transform:scaleY(0.88); opacity:0.8; transform-origin:center center;}
  104. .grace-swiper-card-img-big{transform:scaleY(1); opacity:1; transform-origin:center center; transition:300ms linear;}
  105. </style>