图片轮播 Swipe

基本用法

**注意:因为仅支持触摸事件,所以请打开chrome手机模拟查看demo

图片轮播 Swipe - 图1

  1. <template lang="html">
  2. <main>
  3. <div class="demo-hidden">
  4. <za-panel>
  5. <za-panel-header title="基本"></za-panel-header>
  6. <za-panel-body>
  7. <za-swipe
  8. direction='left'
  9. @changeStart='handleChangeStart'
  10. @changeEnd='handleChangeEnd'>
  11. <za-swipe-item
  12. :key='index'
  13. v-for='(i, index) in ITEMS'>
  14. <div class='swipe-item-pic'>
  15. <span style="display:block;width:100%;height:100px;text-align:center;line-height:100px;">{{i.img}}</span>
  16. </div>
  17. </za-swipe-item>
  18. </za-swipe>
  19. </za-panel-body>
  20. </za-panel>
  21. <za-panel>
  22. <za-panel-header title="纵向"></za-panel-header>
  23. <za-panel-body>
  24. <za-swipe
  25. direction='bottom'
  26. @changeStart='handleChangeStart'
  27. @changeEnd='handleChangeEnd'>
  28. <za-swipe-item
  29. :key='index'
  30. v-for='(i, index) in ITEMS'>
  31. <div class='swipe-item-pic'>
  32. <span style="display:block;width:100%;height:100px;text-align:center;line-height:100px;">{{i.img}}</span>
  33. </div>
  34. </za-swipe-item>
  35. </za-swipe>
  36. </za-panel-body>
  37. </za-panel>
  38. <za-panel>
  39. <za-panel-header title="循环轮播"></za-panel-header>
  40. <za-panel-body>
  41. <za-swipe
  42. ref='swipe'
  43. direction='left'
  44. loop
  45. @changeStart='handleChangeStart'
  46. @changeEnd='handleChangeEnd'>
  47. <za-swipe-item
  48. :key='index'
  49. v-for='(i, index) in ITEMS'>
  50. <div class='swipe-item-pic'>
  51. <span style="display:block;width:100%;height:100px;text-align:center;line-height:100px;">{{i.img}}</span>
  52. </div>
  53. </za-swipe-item>
  54. </za-swipe>
  55. <div class="controls" style="text-align:center;padding-bottom:20px;">
  56. <za-button
  57. size="sm"
  58. @click='onJumpTo'>无动画切换指定页</za-button>
  59. <za-button
  60. size="sm"
  61. style="margin-left:10px;"
  62. @click='onSlideTo'>滑动到指定页</za-button>
  63. </div>
  64. </za-panel-body>
  65. </za-panel>
  66. <za-panel>
  67. <za-panel-header title="自动循环轮播"></za-panel-header>
  68. <za-panel-body>
  69. <za-swipe
  70. direction='left'
  71. loop
  72. auto-play>
  73. <za-swipe-item
  74. :key='index'
  75. v-for='(i, index) in ITEMS'>
  76. <div class='swipe-item-pic'>
  77. <span style="display:block;width:100%;height:100px;text-align:center;line-height:100px;">{{i.img}}</span>
  78. </div>
  79. </za-swipe-item>
  80. </za-swipe>
  81. </za-panel-body>
  82. </za-panel>
  83. </div>
  84. </main>
  85. </template>
  86. <script>
  87. export default {
  88. data() {
  89. return {
  90. ITEMS:[
  91. {
  92. url: '#',
  93. img: "1",
  94. },
  95. {
  96. url: '#',
  97. img: "2",
  98. },
  99. {
  100. url: '#',
  101. img: "3",
  102. }],
  103. }
  104. },
  105. methods: {
  106. handleChangeStart(index){
  107. console.log(index);
  108. },
  109. handleChangeEnd(index){
  110. console.log(index);
  111. },
  112. onJumpTo(){
  113. this.$refs.swipe.onJumpTo(0)
  114. },
  115. onSlideTo(){
  116. this.$refs.swipe.onSlideTo(2)
  117. }
  118. },
  119. };
  120. </script>

API

Swipe Attributes

属性类型默认值可选值/参数说明
prefixClsstringza-swipe类名前缀
directionstring'left''left', 'right', 'top', 'bottom'滑动方向
heightnumber, string高度
loopboolfalse是否循环
autoPlayboolfalse是否自动轮播

Swipe Events

事件名称说明回调参数
changeStart动画开始时触发的事件index, 当前处于激活状态幻灯片的index值
changeEnd动画结束后触发的事件index, 动画结束时处于激活状态幻灯片的index值