graceSwiperCard.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <view>
  3. <swiper :style="{width:width, height:height}" class="grace-swiper-card"
  4. :indicator-dots="true" :interval="interval"
  5. :indicator-color="indicatorColor" :indicator-active-color="indicatorActiveColor"
  6. :duration="500" :circular="true" :autoplay="autoplay"
  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. },
  69. data() {
  70. return {
  71. current : 0,
  72. isReady : false
  73. }
  74. },
  75. methods:{
  76. swiperchange : function (e) {
  77. this.current = e.detail.current;
  78. this.$emit('swiperchange', this.current);
  79. this.isReady = true;
  80. }
  81. }
  82. }
  83. </script>
  84. <style scoped>
  85. .grace-swiper-card-item{box-sizing: border-box; font-size:0; overflow:hidden;}
  86. .grace-swiper-card-image{width:100%;}
  87. .grace-swiper-card-img-small{transform:scaleY(0.88); opacity:0.8; transform-origin:center center;}
  88. .grace-swiper-card-img-big{transform:scaleY(1); opacity:1; transform-origin:center center; transition:300ms linear;}
  89. </style>